当前位置: 首页 > 图灵资讯 > 行业资讯> python单下划线是什么意思

python单下划线是什么意思

来源:图灵python
时间: 2024-08-14 11:13:38

1、说明

和Golang一样,Python不仅可以有方法,还可以定义许多类型甚至基本类型;

Python中没有真正意义上的私有方法或属性,只是表示不应该访问该方法或属性,因为它不是API的一部分。

2、实例

classBaseForm(StrAndUnicode):
...

def_get_errors(self):
"ReturnsanErrorDictforthedataprovidedfortheform"
ifself._errorsisNone:
self.full_clean()
returnself._errors

errors=property(_get_errors)

以上是python单下划线的介绍,希望对大家有所帮助。更多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。