Does anybody know any practical use for the partition() function: print("abcd".partition("c")) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

Does anybody know any practical use for the partition() function: print("abcd".partition("c"))

I found the partition function in a challenge. I can't think of a reason to use it. It looks less usefull than split().When should it be used?

26th May 2022, 7:55 AM
Paul
Paul - avatar
2 Antworten
+ 4
partition() splits at the 1st occurrence of the substring, leaving the substring in the resulting list. split() splits at each occurrence of the substring, excluding the substring from the resulting list. https://code.sololearn.com/c3B4Hs4zxs8I/?ref=app
26th May 2022, 10:29 AM
Lisa
Lisa - avatar
+ 3
Yeah if you want to split a word at any letter. The use case is the use case. If you need it, use it. If not, then don't.
26th May 2022, 8:50 AM
Slick
Slick - avatar