CHAPTER 52 •
PYTHON
Python __init__
Learn how constructors initialize objects.
01 What is this?
Learn how constructors initialize objects.
02 Syntax
Python Syntax
def __init__(self):
03 Example
Python Example
class Student:
def __init__(self, name):
self.name = name
student = Student('AIFA')
print(student.name)
04 Important Points
__init__ runs when an object is created.
05 Common Mistakes
Remember to use self inside instance methods.
06 Real World Use
Constructors initialize object data.
07 Practice This Topic
Now try the example yourself in the AIFA Python Editor.
- Read the example carefully.
- Change the values.
- Run the code.
- Observe the output.
- Try creating your own example.