Convert string to integers | SoloLearn: Learn to code for FREE!

0

Convert string to integers

How to convert “2,3,4” to integers in python ?

4/27/2020 10:46:46 AM

Casc

4 Answers

New Answer

0

First, you transform your string into a list of pure number strings. You can use the string method split for it, which you call with ',' as argument. Then, you can loop over your list and apply int() to each element.

+1

You may find answer in https://www.digitalocean.com/community/tutorials/how-to-convert-data-types-in-python-3

0

num=[„1“,“2“,“3“,“4“,“5“,“6“,“7“,“8“,“9“] for s in str: if s in num: print(int(s))

0

a=input("") x=a.split(',') for i in x: print(int(i ))