26.13. Objects

Python has robust support for object data types. Although a full description of object-oriented programming is beyond the scope of this book, the following sections provide an introduction to Python's handling of objects.

Python is classified as an object-oriented programming language, although you can write useful Python code without using classes and instances. Many Python programmers make good use of Python without taking advantage of its object-oriented features. In Python, everything is an object: list, tuple, string, class, or instance of class.

Python classes are instantiated in the following way. First, define the class like this:

class MyClass:
    def __init__(self):
        #code to execute
    def function1(self,args):
        #code to execute

Then instantiate it like this:

if __name__ == '__main__':
    results = MyClass()

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.