METHODS: FUNCTIONS THAT BELONG TO OBJECTS
A method is simply a function that you call on an object using the form object_name.method_name(arguments) For example, the following session creates the string variable s and assigns it the string object 'Hello'. Then the session calls the object’s lower and upper methods, which produce new strings containing alllowercase and alluppercase versions of the original string, leaving s unchanged:
view code image
In [1]: s = 'Hello'
In [2]: s.lower() # call lower method on string object s
Out[2]: 'hello'
In [3]: s.upper()
Out[3]: 'HELLO'
In [4]: s
Out[4]: 'Hello'
In [2]: s.lower() # call lower method on string object s
Out[2]: 'hello'
In [3]: s.upper()
Out[3]: 'HELLO'
In [4]: s
Out[4]: 'Hello'
The Python Standard Library reference at
https://docs.python.org/3/library/index.html
describes the methods of builtin types and the types in the Python Standard Library. In the “ObjectOriented Programming” chapter, you’ll create custom types called classes and define custom methods that you can call on objects of those classes.