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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started