0
Split('')?
A question asked me about a split() method. I looked though the python course but couldn't find anything on it. Please explain, possible with an example? Thanks!
7 ответов
+ 3
Seth i meant to read my answer, but i can make another example
You want to take input from a user and count how many words are used.
The first thing you wanna do in this case is to split that input into separate words, and that is what you use the split method for.
I updated my original answer and included some syntax, yours is incorrect
+ 4
Note: split() is not a function, it is a method.
It can be used to split a string into a list, i just answered a split() related question, i guess you can use it as an example:
https://www.sololearn.com/Discuss/2660362/?ref=app
Here is some syntax too:
(from w3schools)
string.split(separator, maxsplit)
separator:
Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator
maxsplit:
Optional. Specifies how many splits to do. Default value is -1, which is "all occurrences"
+ 1
Ok. I'll play around with and see if I can understand it. Thanks!!
+ 1
One more question. is there a method for finding the longest item in a list?
+ 1
Oh! That's very helpful! Thanks!
I was gonna try to do it with a for loop xD
0
I can't read that xD
So do you it like: split('test things out')
0
Seth max(), there is a min() method for shortest too