¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita0
Convert string to integers
How to convert “2,3,4” to integers in python ?
4 Respuestas
+ 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.
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 ))