A class variable is a variable common to the class. Instance variables are variables that are used only by that instance. This is a memorandum of understanding for beginners.
Example
class enemy:
#Class variables
#Variables shared between instance objects
ENEMY_MAX = 100 #Maximum number of enemies
CHARACTER = 'O' #Enemy display character
def __init__(self,x,y):
#Instance variables
#Variables not shared between instance objects
self.alive = True #Enemy alive flag
self.x = x #Enemy x coordinate
self.y = y #Enemy y coordinate
To ensure access to class variables, use "class.variable name" both inside and outside the class.
Recommended Posts