+ 2
what is split() func in py?
Please describe split() function of Py. I found nothing but some comments in sololearn. Thanks in advance.
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!)
+ 4
David Ashton
a lot of thanks
+ 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.