gpt4 book ai didi

Python 前导下划线_variables

转载 作者:太空狗 更新时间:2023-10-29 17:03:02 24 4
gpt4 key购买 nike

我们知道在一个类中,以__function__开头的函数在使用时不会被导入:

from module import *

有人问什么是_variable?我从来没有用过。
它们存在吗?这是一个不能使用类对象或其他东西访问的变量概念吗?

最佳答案

这是私有(private)变量的命名约定。见9.6,私有(private)变量:http://docs.python.org/tutorial/classes.html#private-variables

关于Python 前导下划线_variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9998348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com