Python displays every integer within int input

If I am given input 1 2 3 4 5, what is the standard method for splitting such an input and possibly adding 1 to each integer?

I think something like lines splitting an input list and matching each with an integer.

+5
source share
1 answer

You can use list comprehension.

s = "1 2 3 4 5" print [int(i)+1 for i in s.split()] 
+8
source

Source: https://habr.com/ru/post/1231984/


All Articles