How to create List type of Objects in python:-

0


If we want to store information of multiple objects in python or we want to create a list to contain multiple object definitions then we implement this.

Syntax of this:-

class Classname:

      def __init__(self):

var = []

obj = Classame()

var.append(obj)

obj1 = Classname()

var.append(obj1);

.Now I am solving this real-time problem 

WAP to display the greatest marks of three different students, using (no, name and marks field) to creating constructor, logic method, and separate display method?

class Student:

    result = ""

    def __init__(self,rno,name,marks):

        self.rno=rno

        self.name=name

        self.marks=marks

    def logic(s):

        m=0

        for st in s:

            if m<st.marks:

                m=st.marks

                Student.result = str(st.rno) + " "+ st.name +  " "+str(st.marks)

    def display():

        print("Result is "+Student.result)

      students =[]

stu1 = Student(1001,"Manish",430)

students.append(stu1)

stu2 = Student(1002,"Jay",450)

students.append(stu2)

stu3 = Student(1003,"Ravi",330)

students.append(stu3)

#students = [stu1,stu2,stu3]

Student.logic(students)

Student.display()

Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)