变量
变量是指向某个值的名称。
1. 赋值语句
用于新建变量,并为该变了赋值。
>>> num = 18
>>> message = 'Hi, Python!'
2. 变量名命名规范
- 只能是 字母、数字 或 下划线 的任意组合
- 变量名的第一个字符 不能是数字
- 变量名不能为 Python关键字, 用 help(‘keywords') 查看
>>> help('keywords') # 默认为 Python3
Here is a list of the Python keywords. Enter any keyword to get more help.
False def if raise
None del import return
True elif in try
and else is while
as except lambda with
assert finally nonlocal yield
break for not
class from or
continue global pass
- 变量名命名要有意义,用 英文单词 表达, 最好不要用拼音
- 命名方式
驼峰体 AgeOfLuffy = 22
下划线 age_of_luffy = 22
- 常量(全为大写)
PI = 3.1415926