class variable, instance variable

class Apple(object):
    name = 'apple'
p1 = Apple()
p2 = Apple()
p1.name = 'orange'
print(p1.name)
print(p2.name)


''' Ordinary variable (non-class variable), the variable exists after being assigned a value. The variables of the class can be assigned outside the def in the class, through the
variable name, and can be assigned through the class object in the def'''

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771686&siteId=291194637