Language Syntax

Class definition — Python syntax

Execute the class body to populate a namespace, then construct and bind a class using the selected metaclass. Class attributes are shared through lookup; instance assignment can shadow them.

Formal Syntax & Structure

python syntaxpython
class Name(bases):    suite

Working Example

Example Snippetpython
class Product:    currency='USD'    def __init__(self,price):        self.price=pricep=Product(7)print((p.price,p.currency))
Python Reference