python separate string by comma code example
Example 1: how to split an input in python by comma
lst = input().split(',')
print (lst)
lst = input().split(' ; ')
print (lst)
Example 2: split a string by comma python
txt = "hello, my name is Peter, I am 26 years old"
x = txt.split(",")
print(x)
for thing in x:
print(thing)
Example 3: split string python
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
Example 4: how to split word in python
text= "I am Batman"
splitted_text= text.split()
Print(splitted_text)
Example 5: split a string by comma in python
str = 'apple,orange,grape'
chunks = str.split(',')
print(chunks)