+ 8

Why is .split() and .split(sep=None) works as same?

On performing the .split operation on a string we can use .split() or .split(sep=None) . Why two commands perform the same task?

15th Jun 2019, 1:22 PM
Gaurav Das
Gaurav Das - avatar
3 odpowiedzi
+ 7
The default value of the set argument is None. You can check the docs.
15th Jun 2019, 1:40 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
In Python, you have default arguments that kick in when you don't give an argument. I guess, the definition of split looks somewhat like this: def split(self,..., sep=None): if sep==None: ... else: ... So by explicitly passing sep as None, you're just overwriting, what's in there anyway.
15th Jun 2019, 1:38 PM
HonFu
HonFu - avatar