So, I have learnt that strings have a center method.
>>> 'a'.center(3)
' a '
Then I have noticed that I can do the same thing using the 'str' object which is a type, since
>>> type(str)
<type 'type'>
Using this 'type' object I could access the string methods like they were static functions.
>>> str.center('a',5)
' a '
Alas! This violates the zen of python.
There should be one-- and preferably only one --obvious way to do it.
Even the types of these two methods are different.
>>> type(str.center)
<type 'method_descriptor'>
>>> type('Ni!'.center)
<type 'builtin_function_or_method'>
Now,
- Is this an example of how classes in python should be designed?
- Why are the types different?
- What is a method_descriptor and why should I bother?
Thanks for the answers!
See Question&Answers more detail:os