9/23/2020

Python explanations

Hello!
This is the question today.

Write a Composer class that has three instance variables:

  1. name
  2. dob
  3. 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 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...