类的实例化,self

class Person:
x = 'abc'

def __init__(self, name, age=19):
self.name = name
self.y = age
#print("pengjai")

def show(self,y):
# print(x)
Person.x = y


tom=Person("jia")
tom.show(2) #self就是实例化对象
Person.show(2,8) #直接将self当做形参来

猜你喜欢

转载自www.cnblogs.com/pengwa1226/p/10296780.html