双下划线开头的变量实现了类私有变量功能
发布日期:2021-05-06 21:50:14 浏览次数:25 分类:精选文章

本文共 285 字,大约阅读时间需要 1 分钟。

class Test():

    __ss=9
    ss=10
    _s=20

print(Test.__ss)

提示错误;

print(Test.__dict__)

{'__module__': '__main__', '_Test__ss': 9, 'ss': 10, '_s': 20, '__dict__': <attribute '__dict__' of 'Test' objects>, '__weakref__': <attribute '__weakref__' of 'Test' objects>, '__doc__': None}

可以看到不存在 __ss变量

 

上一篇:stacking与blending的区别
下一篇:ast.literal_eval

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月05日 15时04分41秒