Class Object

#!/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): = name
        self.marks = science + history + math
    # Method of the class
    def displayMarks(self):
        print("Total marks of",, "=", 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'

#***** Output *****
Total marks of James = 190
Total marks of Jonh = 150

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!