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!

9th Jan 2021, 4:04 PM
Seth
Seth - avatar
7 Respostas
+ 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
9th Jan 2021, 4:15 PM
Qwerty Uiop
Qwerty Uiop - avatar
+ 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"
9th Jan 2021, 4:08 PM
Qwerty Uiop
Qwerty Uiop - avatar
+ 1
Ok. I'll play around with and see if I can understand it. Thanks!!
9th Jan 2021, 4:19 PM
Seth
Seth - avatar
+ 1
One more question. is there a method for finding the longest item in a list?
9th Jan 2021, 4:26 PM
Seth
Seth - avatar
+ 1
Oh! That's very helpful! Thanks! I was gonna try to do it with a for loop xD
9th Jan 2021, 5:23 PM
Seth
Seth - avatar
0
I can't read that xD So do you it like: split('test things out')
9th Jan 2021, 4:10 PM
Seth
Seth - avatar
0
Seth max(), there is a min() method for shortest too
9th Jan 2021, 4:37 PM
Qwerty Uiop
Qwerty Uiop - avatar