Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Convert string to integers
How to convert ā2,3,4ā to integers in python ?
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.
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 ))