def x(): return 1 x.y = 2 print(x()) print(x.y)
输出:
1 2
我的问题是如何从函数体中添加
y
上课有什么问题吗?
class func(): x = 1 y = 2 print(func.x) print(func.y)