Skip to content

Python convert list of strings to ints (Integer) | Example code

  • by

Use map() method to convert a list of strings to ints in Python. For example, want to convert all strings in a list to integers.

list = ['1', '2', '3']

How do I make it:

results = [1, 2, 3]

Python Example convert list of strings to ints

Simple python example code.

Use map(function, iterable) with a list of strings as iterable and int as function to apply int() to each string in the list. Use list(iterable) with the output of map() as iterable to convert to a list.

string_list = ["1", "2", "3"]

integer_map = map(int, string_list)

Maps each string to an int

integer_list = list(integer_map)

Converts mapped output to a list of ints



Python convert list of strings to ints

Do comment if you have any doubts and suggestions on this python list code.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *