Chapters
Python114 chapters

ReferenceKeywords

class

Defines a new type. Objects made from it get its methods.

Signature

class Name(Parent):

Returns

Nothing; it binds the name to a class object.

Example

Python
class Dog:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return f"{self.name} woofs"

print(Dog("Rex").speak())

Output

Rex woofs

See also