Have a look at the below code. I have put comments wherever required for better understanding.
# create Student class
class Student:
# create the constructor
def __init__(self,name,id,age,gender):
self.name = name
self.id = id
self.age = age
self.gender = gender
# Getters
def getName(self):
return self.name
def getAge(self):
return self.age
# Setters
def setId(self,id):
self.id = id
def setGender(self,gender):
self.gender = gender
# create an object of class student
student = Student('Alexa',1,23,'Female')
# print all the attributes
print(student.getName())
print(student.getAge())
print(student.id)
print(student.gender)
Happy Learning!
Get Answers For Free
Most questions answered within 1 hours.