by Sai gowtham

How to convert all strings in a list to ints in Python

In this tutorial, we are going to learn about how to convert all strings in a list to integers in Python.

Consider, we have a following prices list:

prices = ['2', '3', '4']

Now, we need to convert the above list of strings to a list of integers like this:

[2, 3, 4]

Converting list of strings to integers

To convert the list of strings to integers, we can use the built-in map() function in Python.

Here is an example:

prices = ['2', '3', '4']
int_map = map(int, prices)
int_list = list(int_map)

print(int_list)

Output:

[2, 3, 4]

In the code above, the map() function applies the int() to each iterable in the list and converts it to ints, then we have passed the map() output to list() function to convert it to a list.

Similarly, we can also do it by using a list comprehension syntax in Python.

prices = ['2', '3', '4']
int_list = [int(el) for el in prices]

print(int_list)

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
152,857 students enrolled
48.5 hours of video content
View Course