For converting a list of strings that are all integers, into a list of integers we use a built-in map function.
The map ( function, iterable, … ) function transforms all items in an iterable ( ex : lists, tuples, and strings ) by applying the function on them.
Thus we pass the below to the map function..
Below program accepts an input list of space separated integers and converts them into a list of integers.
Python3 : Converting a list of integers in string format to a list of int
def main():
_list_int = list(map(int, input("Enter string of space separated integers : ").split()))
print ("Numbers incremented...")
for num in _list_int:
print(num+1)
if __name__ == "__main__":
main()
Output
Enter string of space separated integers : 1 2 3 4 5 6
Numbers incremented...
2
3
4
5
6
7
© 2019-2026 Algotree.org | All rights reserved.
This content is provided for educational purposes. Feel free to learn, practice, and share knowledge.
For questions or contributions, visit algotree.org
"There are only two hard things in Computer Science: cache invalidation and naming things. - Phil Karlton"