+ 1
I tried 'abc'.split() to get ['a' ,'b', 'c'] as output but the output is ['abc'] , why and how can I get my desired output ?
7 Answers
+ 7
Since there is no seperator in the string you provided, and split takes two parameter, one seperator second number of max split.. so split won't work here..
u can try this:
list('abc') would return ['a','b','c']
+ 7
Another version:
print('abc'.replace('',', '))
+ 5
Print('a,b,c'.split(","))
And out put is ['a','b','c']
+ 4
Rik Wittkopp, wow, you can substitute nothing against something?
That's funny. š
And interesting, didn't know that!
+ 3
Sami Khan thanks for explaining why it was not working and how it can be done by simply converting it into a list.
+ 3
HonFu Wish I could do the same with my income. š¤£