spam = "A B C D"
eggs = "E-F-G-H"
# the split() function will return a list
spam_list = spam.split()
# if you give no arguments, it will separate by whitespaces by default
# ["A", "B", "C", "D"]
eggs_list = eggs.split("-", 3)
# you can specify the maximum amount of elements the split() function will output
# ["E", "F", "G"]
def split(word):
return [char for char in word]
# Driver code
word = 'geeks'
print(split(word))
#Output ['g', 'e', 'e', 'k', 's']
string = 'James Smith Bond'
x = string.split(' ') #Splits every ' ' (space) in the string to a list
# x = ['James','Smith','Bond']
print('The name is',x[-1],',',x[0],x[-1])
s = 'KDnuggets is a fantastic resource'
print(s.split())
# Output
# ['KDnuggets', 'is', 'a', 'fantastic', 'resource']
# By default, split() splits on whitespace,
# but other character(s) sequences can be passed in as well.
s = 'these,words,are,separated,by,comma'
print('',' separated split -> {}'.format(s.split(',')))
s = 'abacbdebfgbhhgbabddba'
print(''b' separated split -> {}'.format(s.split('b')))
# ',' separated split -> ['these', 'words', 'are', 'separated', 'by', 'comma']
# 'b' separated split -> ['a', 'ac', 'de', 'fg', 'hhg', 'a', 'dd', 'a']