大驼峰命名法
大驼峰命名法
一、大驼峰是什么
大驼峰(PascalCase / 大驼峰命名法):
所有单词首字母大写,单词之间不加下划线,直接拼接。
二、规则对比
表格
| 命名方式 | 写法示例 | 用途 (Python) |
|---|---|---|
| 大驼峰 PascalCase | StudentInfo、CarBrand |
类名专用 |
| 小驼峰 camelCase | studentInfo、carBrand |
一般不用在 Python,前端 JS 常用 |
| 下划线 snake_case | student_info、car_brand |
变量 / 函数 / 文件名 |
三、Python 强制习惯:类必须用大驼峰
✅ 正确(定义类)
# 大驼峰:每个单词首字母大写
class Student:
pass
class PersonInfo:
pass
class MobilePhone:
pass
❌ 错误示范
class student: # 小写不行
class student_info: # 下划线不行
class personinfo: # 全连写分不清单词
四、结合刚才「类和对象」举例
# 类 → 大驼峰
class MobilePhone:
def __init__(self, brand):
# 变量 → 下划线/小字母
self.phone_brand = brand
# 对象、变量 → 小写+下划线
my_phone = MobilePhone("华为")
五、快速记忆
- 类名 = 大驼峰(像人名:LiMing、WangHong)
- 变量 / 函数 = 下划线(user_name、get_info)
- 全程不用空格、横杠。

浙公网安备 33010602011771号