This is the question today.
Write a
Composer
class that has three instance variables:
- name
- dob
- country
Add an additional class variable
.count
which counts the total number of instances created.
From : Counting Instances Created from a Class // Edabit
My code is this.
counter = 0
class Composer:
def __init__(self, name, dob, country):
global counter
self.name = name
self.dob = dob
self.country = country
counter += 1
def count():
global counter
return counter
So, I'll talk about classes.
Classes are Instance's plan, I just made a image to make the think into your mind.
Code is simple, when the instance is made, plus the counter by 1.
Bye!!
0 件のコメント:
コメントを投稿