Python 3 Fundamentals & OOP
20 mins read
Free Lesson
Define classes, the __init__ constructor, instance methods, self keyword, and class inheritance.
OOP in Python
class Course:
def __init__(self, title: str, is_free: bool = True):
self.title = title
self.is_free = is_free
self.students = []
def enroll_student(self, student_name: str) -> None:
self.students.append(student_name)
print(f"{student_name} enrolled in {self.title}")
def __str__(self) -> str:
return f"Course({self.title}, Free={self.is_free})"