Python ClassesLesson 38Free preview
Python Classes/Objects
This lesson is part of Python · All levels
Summary
A class in Python is defined by the keyword class and contains the attribute as data and the method as behavior. Object is created by calling a class name as a function, e.g. person = Orang("Dewi"), and this process is called instance. Each object keeps its own copy of the attribute instance so that the data is not mixed between objects.
Key points
- The class definition is written class NameClass: then the class body is indented.
- Object is created by name_object = NamaClass(argumen); this method is called instance.
- The attribute instance is written self.nama_atribut, usually filled in the __init__ method.
- Method is called by object with syntax object.method().
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.