编辑“︁
Python
”︁(章节)
跳转到导航
跳转到搜索
Template:Editnotice load/content
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
=== 标识符 === [[标识符]]就是名字,在[[ASCII]]范围内(U+0001..U+007F),可用于标识符的字符为:大写字母<code>A</code>至<code>Z</code>和小写字母<code>a</code>至<code>z</code>,下划线<code>_</code>以及数字<code>0</code>至<code>9</code>,但首字不可以用数字。如下[[命名规则 (程序设计)|命名约定]]<ref>{{cite web|url=https://www.python.org/dev/peps/pep-0008/#naming-conventions|title=PEP 8 – Style Guide for Python Code - Naming Conventions|accessdate=2017-10-06|archive-date=2018-07-13|archive-url=https://web.archive.org/web/20180713002451/https://www.python.org/dev/peps/pep-0008/#naming-conventions|dead-url=no}}</ref>,是为“保留标识符类”<ref>{{cite web|url=https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers|title=The Python Language Reference - 2. Lexical analysis - Reserved classes of identifiers|access-date=2023-03-03|archive-date=2018-01-09|archive-url=https://web.archive.org/web/20180109063410/https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers|dead-url=no}}</ref>: * <code>_spam</code>(单下划线开头):弱“内部使用”标识。对于<code>from M import *</code>,将不导入所有以下划线开头的对象。 * <code>spam_</code>(单下划线结尾):为了避免与python关键字的命名冲突。 * <code>__spam</code>(双下划线开头):在命名一个类[[特性 (计算机科学)|特性]]的时候,采用[[名字修饰]],比如在类<code>SpamEggs</code>内,<code>__spam</code>将变成<code>_SpamEggs__spam</code><ref name="private-var">{{cite web |url=https://docs.python.org/3/tutorial/classes.html#private-variables |title=9.6. Private Variables |accessdate=2020-09-27 |archive-date=2012-10-23 |archive-url=https://web.archive.org/web/20121023030209/http://docs.python.org/tutorial/classes.html#private-variables |dead-url=no }}</ref>。 * <code>__spam__</code>(双下划线开头双下划线结尾):指那些包含在用户控制的[[命名空间]]中的“魔术”方法或[[特性 (计算机科学)|特性]],比如<code>__delattr__</code>、<code>__dir__</code>、<code>__doc__</code>、<code>__getattribute__</code><ref>{{cite web|url=https://docs.python.org/3/whatsnew/2.2.html#attribute-access|title=What’s New in Python 2.2 — Attribute Access}}</ref>、<code>__init__</code>、<code>__new__</code>、<code>__repr__</code>、<code>__setattr__</code>、<code>__sizeof__</code>等。建议永远不要将这样的命名方式应用于自己的变量或函数。
摘要:
请注意,所有对Local Chinese Wikipedia的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Project:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
大陆简体
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息