+ 2

what is split() func in py?

Please describe split() function of Py. I found nothing but some comments in sololearn. Thanks in advance.

21st Mar 2020, 5:49 PM
Python piper
Python piper - avatar
5 odpowiedzi
+ 15
print("abcd".split("c")) # output ["ab", "d"] print("Hello World!".split()) # output ["Hello", "World!"] The opposite is str.join(), e.g. print(" ".join(["Hello", "World!"])) # output "Hello World!" print("c".join(["ab", "d"])) # output "abcd" You can use these to remove spaces print("".join("abc d".split())) # output "abcd" (edited, thanks to Kevin Star for pointing out my mistake!)
21st Mar 2020, 10:22 PM
David Ashton
David Ashton - avatar
21st Mar 2020, 5:53 PM
Kevin ★
+ 4
David Ashton a lot of thanks
22nd Mar 2020, 6:15 AM
Python piper
Python piper - avatar
+ 2
It seperates strings you can use like this: WORD.split( ) default value is " " but you can also write another things like WORD.split("=") or WORLD.split("/") and the output will be a list but there wont be = or / in the list.
21st Mar 2020, 6:00 PM
meow
meow - avatar