how to split string with comma in python
# We can use the split() function and put a "," in the parameter
# It'll return a list with the string split up by commas.
txt = "hello, my name is Peter, I am 26 years old"
x = txt.split(",")
print(x)
# You can also do this
for thing in x:
print(thing)
4
1
str = 'apple,orange,grape'
#split string by ,
chunks = str.split(',')
print(chunks)
Thank you!
1
0
4.33
9
# We can use the split() function and put a "," in the parameter
# It'll return a list with the string split up by commas.
txt = "hello, my name is Peter, I am 26 years old"
x = txt.split(",")
print(x)
Thank you!
9
0
Are there any code examples left?
New code examples in category Python