Keywords and Control Flow

class — Class definition

Execute a class body in a class namespace and construct a class object using the selected metaclass. With ordinary type construction the resulting class can be instantiated; a custom metaclass or decorator may change the result. Class attributes are shared through attribute lookup, whereas instance attributes belong to individual instances. Methods do not normally capture the class namespace as an enclosing lexical scope. Inheritance uses the method resolution order; class decorators run after class creation.

Formal Syntax & Structure

python syntaxpython
class Name:    suite
class Name(Base, metaclass=Meta):    suite

Working Example

Example Snippetpython
class Ticket:    category = "standard"
    def __init__(self, number):        self.number = number
first = Ticket(12)second = Ticket(15)print(first.category, first.number)print(second.category, second.number)
Python Reference