python命名规范

小结:

1、命名组成:

  • 标示符可以由 字母下划线 和 数字 组成

  • 不能以数字开头

  • 不能与关键字重名

2、命名要求:

  • 见名知意

3、命名举例:

  • 变量名:全小写单词,下划线连接
  • 类命名:(大驼峰)所有单词首字母大写,直接拼接
  • 常量名:全大写单词,下划线连接

 4、驼峰法

  • 当 变量名 是由二个或多个单词组成时,还可以利用驼峰命名法来命名

  • 小驼峰式命名法

    • 第一个单词以小写字母开始,后续单词的首字母大写

    • 例如:firstNamelastName

  • 大驼峰式命名法

    • 每一个单词的首字母都采用大写字母

    • 例如:FirstNameLastNameCamelCase

Python之父Guido推荐的规范

TypePublicInternal
Moduleslower_with_under_lower_with_under
Packageslower_with_under 
ClassesCapWords_CapWords
ExceptionsCapWords 
Functionslower_with_under()_lower_with_under()
Global/Class ConstantsCAPS_WITH_UNDER_CAPS_WITH_UNDER
Global/Class Variableslower_with_under_lower_with_under
Instance Variableslower_with_under_lower_with_under (protected) or __lower_with_under (private)
Method Nameslower_with_under()_lower_with_under() (protected) or __lower_with_under() (private)
Function/Method Parameterslower_with_under 
Local Variableslower_with_under 

转载于:https://www.cnblogs.com/andy9468/p/10229115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值