Convert the list of strings to int Python | Example code

Use map() function to convert the list of strings to int in Python. Maps each string to an int and Converts mapped output to a list of ints.

How to convert a list of strings to ints in Python

Simple example code converting a list of strings to ints converts each string in the list into an integer.

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

i_map = map(int, s_list)

res = list(i_map)

print(res)

Output:

Convert the list of strings to int Python

Do comment if you have any doubts and suggestions on this Python example code.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.