SPLIT is not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

SPLIT is not working

i tried to work on split but it showed some error also I tried to google but not got right. code- 'hi-my-name-'. split(-) error- EOL while scanning string literal >>>

16th May 2020, 3:14 AM
DSC11
DSC11 - avatar
6 Answers
+ 5
You should enclose the hyphen symbol with quotes 'hi-my-name-'.split('-') will work
16th May 2020, 3:31 AM
deeyae
deeyae - avatar
+ 4
s = 'hi-my-name-'.split('-') print(s) # ['hi', 'my', 'name', ''] If you don't want the empty strings from leading and trailing '-' characters; s = 'hi-my-name-'.strip('-').split('-') print(s) # ['hi', 'my', 'name']
16th May 2020, 3:35 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thanks
16th May 2020, 3:44 AM
DSC11
DSC11 - avatar
+ 1
you need to put the parameter of the split function between quotes
16th May 2020, 3:34 AM
Emanuel Maliaño
Emanuel Maliaño - avatar
+ 1
Single code '-'
17th May 2020, 3:21 PM
Wei Phyo Aung
Wei Phyo Aung - avatar
0
'h-ell-o'.split('-')
16th May 2020, 3:35 AM
Emanuel Maliaño
Emanuel Maliaño - avatar