Class Variables in OOPs in Python
class Student:
age = 10
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def user_info(self): # Method
print(f"{self.first_name} {self.last_name} is {Student.age} years old.")
s1 = Student("Adrika", "Bhadauria")
print(s1.first_name)
print(s1.last_name)
print(s1.age)
s1.user_info()
print(s1.__dict__)
s2 = Student("Anika", "Singh")
print(s2.first_name)
print(s2.last_name)
print(s2.age)
s2.user_info()
print(s2.__dict__)
Post a Comment