1def split(word):
2 return [char for char in word]
3
4# Driver code
5word = 'geeks'
6print(split(word))
7
8#Output ['g', 'e', 'e', 'k', 's']
1string phrase = "The quick brown fox jumps over the lazy dog.";
2string[] words = phrase.Split(' ');
3
4foreach (var word in words)
5{
6 System.Console.WriteLine($"<{word}>");
7}
8
1foo = "A B C D"
2bar = "E-F-G-H"
3
4# the split() function will return a list
5foo_list = foo.split()
6# if you give no arguments, it will separate by whitespaces by default
7# ["A", "B", "C", "D"]
8
9bar_list = bar.split("-", 3)
10# you can specify the maximum amount of elements the split() function will output
11# ["E", "F", "G"]
1string = 'James Smith Bond'
2x = string.split(' ') #Splits every ' ' (space) in the string to a list
3# x = ['James','Smith','Bond']
4print('The name is',x[-1],',',x[0],x[-1])
1>>> '1,2,3'.split(',')
2['1', '2', '3']
3>>> '1,2,3'.split(',', maxsplit=1)
4['1', '2,3']
5>>> '1,2,,3,'.split(',')
6['1', '2', '', '3', '']
7
1file='/home/folder/subfolder/my_file.txt'
2file_name=file.split('/')[-1].split('.')[0]