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
To expand on RichieHindle's answer:
In Python, all methods on a class idiomatically take a "self" parameter. For example:
def method(self, arg): pass
That "self" argument tells Python what instance of the class the method is being called on. When you call a method on a class instance, this is typically passed implicitly for you:
o.method(1)
However, you also have the option of using the class Object, and explicitly passing in the class instance:
C.method(o, 1)
To to use your string example, str.center is a method on the str object:
"hi".center(5)
is equivalent to:
str.center("hi", 5)
You are passing in the str instance "hi" to the object, explicitly doing what's normally implicit.