0

why built in functions with the same purpose in python are called differently

the list function: s = 'spam' t = list(s) split : s = 'pining for the fjords' t = s.split() so why list function can't be called like s.list() and or why the split can't be called like t=split(s) , I know that one takes argument , another not, but they serve almost the same purpose

22nd Feb 2022, 12:24 AM
sum fatt
4 ответов
+ 2
list() does not work on just one type, so it can't be a method. .split() on the other hand works just with strings.
22nd Feb 2022, 12:54 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Look up the difference between functions and methods.
22nd Feb 2022, 12:31 AM
Simon Sauter
Simon Sauter - avatar
+ 1
and when I want to think about the purpose of them both, which is turning a string into a list, how would I know or remember that list a function and split is a method ?
22nd Feb 2022, 12:50 AM
sum fatt