Mon Aug 02 2021
Class Object
Python Programming3003 views
File Name: class-object.py
#!/usr/bin/evn python
# Define a class as 'student'
class student:
# Constructor with parameters
# The first argument of constructor reference to the current instance of the class
def __init__ (self, name, science, history, math):
self.name = name
self.marks = science + history + math
# Method of the class
def displayMarks(self):
print("Total marks of", self.name, "=", self.marks)
# 'stu1' & 'stu2' are the object of the class 'student'
stu1 = student("James", 50,60,80)
stu2 = student("Jonh", 80,50,20)
# Calling method of the class 'student'
stu1.displayMarks()
stu2.displayMarks()
Reference:
Author:Geekboots