0

Convert string to integers

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

27th Apr 2020, 10:46 AM
Casc
Casc - avatar
4 Respostas
+ 1
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.
27th Apr 2020, 10:49 AM
HonFu
HonFu - avatar
0
num=[„1“,“2“,“3“,“4“,“5“,“6“,“7“,“8“,“9“] for s in str: if s in num: print(int(s))
27th Apr 2020, 10:49 AM
Alexander Thiem
Alexander Thiem - avatar
0
a=input("") x=a.split(',') for i in x: print(int(i ))
27th Apr 2020, 11:14 AM
ANJALI SAHU