How to add an integer to each element in a list?

StackOverflow

If I have list=[1,2,3] and I want to add 1 to each element to get the output [2,3,4], how would I do that?

I assume I would use a for loop but not sure exactly how.

Answer rating: 193

new_list = [x+1 for x in my_list]




Get Solution for free from DataCamp guru