Python podzielić zdanie na słowa
sentence = 'Hello world a b c'
split_sentence = sentence.split(' ')
print(split_sentence)
Stormy Seal
sentence = 'Hello world a b c'
split_sentence = sentence.split(' ')
print(split_sentence)
def split(word):
return [char for char in word]
# Driver code
word = 'geeks'
print(split(word))
#Output ['g', 'e', 'e', 'k', 's']
string = '1-2-3
array_of_words = string.split('-')
print(array_of_words) # prints ['1', '2', '3']
##################################################
#if you dont pass anything in the split() function,
#the default parameter will be a space
##################################################
string = '1 2 3'
array_of_words = string.split()
print(array_of_words) # prints ['1', '2', '3']
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
text= "I am Batman"
splitted_text= text.split()
Print(splitted_text)
>>> mary = 'Mary had a little lamb'
>>> mary.split('a') # splits on 'a'
['M', 'ry h', 'd ', ' little l', 'mb']
>>> hi = 'Hello mother,\nHello father.'
>>> print(hi)
Hello mother,
Hello father.
>>> hi.split() # no parameter given: splits on whitespace
['Hello', 'mother,', 'Hello', 'father.']
>>> hi.split('\n') # splits on '\n' only
['Hello mother,', 'Hello father.']