Question: I'm stuck on a question for my Python Programming Assignment, has to do with classes. If I wanted to write code for a class named

I'm stuck on a question for my Python Programming Assignment, has to do with classes. If I wanted to write code for a class named "Student," and I wanted to create a different variable for each instance of the Student class, how would I go about this? for example, in my class Student, I want to create a variable "self.ID" , and I want this variable to equal to 1 for it's first instance called, and every time new instances get created, the self.ID goes up by one, so for example:

class Student:

def __init__(self, name):

self.name = name

self.ID = ?????

>>> s1 = Student(Marvin)

>>> s2 = Student(Doug)

I want s1 to have variable ID 1, and I want s2 to have variable ID 2, and so on for future instances. How do I go about this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!