Python命名规范

Python之父Guido推荐了命名规范,单下划线开头的模块变量或函数是protected的,from module import *时不包含;双下划线开头的实例变量或方法在类内是私有的,同时应避免使用单字符名称,计数器和迭代器除外。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python之父Guido推荐的规范

单下划线(_)开头表示模块变量或函数式protected的(使用from module import *时不会包含)
双下划线(__)开头的实例变量或方法表示在类内是私有的

应避免使用单字符名称,除了计数器和迭代器

TypePublicInternal(在类内是保护或私有的或仅模块内可用)
Modules(模块)lower_with_under_lower_with_under
Packages(包)lower_with_under
Classes(类)CapWords_CapWords
Exceptions(异常)CapWords
Functions(函数)lower_with_under()_lower_with_under()
Global/Class Constants(全局/类常量)CAPS_WITH_UNDER_CAPS_WITH_UNDER
Global/Class Variables(全局/类变量)lower_with_under_lower_with_under
Instance Variables(实例变量)lower_with_under_lower_with_under
Method Names(方法名)lower_with_under()_lower_with_under()
Function/Method Parameters(函数/方法参数)lower_with_under
Local Variables(局部变量)lower_with_under
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值