Transform String List to Integer in Python (Example Code)

In this Python tutorial you’ll learn how to transform character strings in a list object from string to integer.

Introducing Example Data

x = ['5', '1', '4', '9', '7', '2', '4', '4']    # Constructing example list
print(x)
# ['5', '1', '4', '9', '7', '2', '4', '4']

Example: Converting List Items from Character to Integer

x_integer = [int(i) for i in x]                 # Using list comprehension
print(x_integer)
# [5, 1, 4, 9, 7, 2, 4, 4]

Further Resources & Related Articles

Below, you can find some further resources on topics such as character strings and data conversion.

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top