返回顶部

收藏

生成类属性

更多
class SharedData:
     spam = 42                    # generates a class attribute

x = SharedData()                  # make 2 instances
y = SharedData()
print x.spam, y.spam              # they inherit and share spam

SharedData.spam = 99
print x.spam, y.spam, SharedData.spam

x.spam = 88
print x.spam, y.spam, SharedData.spam

标签:Python,Class

收藏

0人收藏

支持

0

反对

0

发表评论