PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.
#!/usr/bin/python # Filename: method.py class Person: def sayHi(self): print 'Hello, how are you?' p = Person() p.sayHi() # This short example can also be written as Person().sayHi()
Output
$ python method.py Hello, how are you?
How It Works
Here we see theself in action. Notice that thesayHi method takes no parameters but still has the self in the function definition.