一、查看Python版本
python -V #终端命令
二、标识符(变量名)
1.以字母或者下划线开头,
2.其他部分有字母,数字,下划线组成
3.对大小写敏感
三、关键字
python关键字,不能用来当做变量的命名,python标准库提供了key word 模板,可以输出当前版本所有关键字
import keyword
keyword.list
四、python注释,单行——以#开头,快捷键是control加斜杠
多行——多个#,或者'''或者"""
例如:
'''
第一个注释
第二个注释
'''
或者
"""
第三个注释
第四个注释
"""
五、行与缩进
python具有特色的一点,使用缩进表示代码块,不需要使用{}
缩进的空格数是可变的,但是同一代码块的缩进空格数必须一样。
例如
if TRUE :
print(TRUE)
else:
print(False)
if True: print ("Answer") print ("True") else: print ("Answer") print ("False") # 缩进不一致,会导致运行错误
六、多行语句
使用反斜杠(\)来实现多行
total = 'item_one'+\
'item_two'+\
'item_three'
在 [], {}, 或 () 中的多行语句,不需要使用反斜杠(\),例如:
total = ['item_one', 'item_two', 'item_three', 'item_four', 'item_five']
七、数字类型
python有四种数字类型,整数,布尔型,浮点数,复数
int(整数)
bool(布尔)如True
float(浮点数)如1.23
complex(复数)如1+2j