|
| 1 | +class ClassName: |
| 2 | + """This is my first class.""" |
| 3 | + pass |
| 4 | + |
| 5 | + |
| 6 | +class Student: |
| 7 | + def __init__( |
| 8 | + self, |
| 9 | + student_id: str, |
| 10 | + name: str, |
| 11 | + age: int |
| 12 | + ) -> None: |
| 13 | + self.student_id = student_id |
| 14 | + self.name = name |
| 15 | + self.age = age |
| 16 | + self.courses = [] # self.courses = list() |
| 17 | + |
| 18 | + def register(self, course): |
| 19 | + if course not in self.courses: |
| 20 | + self.courses.append(course) |
| 21 | + |
| 22 | + def drop(self, course): |
| 23 | + if course in self.courses: |
| 24 | + self.courses.remove(course) |
| 25 | + |
| 26 | + def __str__(self): |
| 27 | + return f"We have a student with the following information: {self.student_id}, {self.name}, {self.age}" |
| 28 | + |
| 29 | + def __repr__(self): |
| 30 | + return f"Student(\"7\", \"Bora Canbula\", 39)" |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == "__main__": |
| 34 | + object_name = ClassName() |
| 35 | + print(object_name) |
| 36 | + print(hex(id(object_name))) |
| 37 | + print(dir(object_name)) |
| 38 | + print(object_name.__doc__) |
| 39 | + # print(help(object_name)) |
| 40 | + print(object_name.__class__) |
| 41 | + print(object_name.__class__.__name__) |
| 42 | + print(object_name.__class__.__bases__) |
| 43 | + print(object_name.__class__.__module__) |
| 44 | + |
| 45 | + print(isinstance(object_name, ClassName)) |
| 46 | + print(isinstance(object_name, int)) |
| 47 | + print(isinstance(object_name, object)) |
| 48 | + |
| 49 | + print(issubclass(ClassName, object)) |
| 50 | + |
| 51 | + """ |
| 52 | + a = 5 |
| 53 | + print(isinstance(a, int)) |
| 54 | + print(isinstance(a, object)) |
| 55 | + """ |
| 56 | + |
| 57 | + student = Student("7", "Bora Canbula", 39) |
| 58 | + print(student.student_id) |
| 59 | + print(student.name) |
| 60 | + print(student.age) |
| 61 | + print(student.courses) |
| 62 | + student.register("CSE 3244") |
| 63 | + print(student.courses) |
| 64 | + student.register("CSE 3237") |
| 65 | + print(student.courses) |
| 66 | + student.drop("CSE 3237") |
| 67 | + print(student.courses) |
| 68 | + print(student) |
| 69 | + print(student.__repr__()) |
| 70 | + recreated_student = eval(repr(student)) |
| 71 | + print(recreated_student) |
0 commit comments