python保留字及关键字
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
注释可使用#、''' 、"""
三种格式
#!/usr/bin/python3
#第一个注释
#第二个注释
'''
第三个注释
第四个注释
'''
"""
第五个注释
第六个注释
"""
print("hello world")
输出结果:
[root@bogon lqw]# ./hello.py
hello world
python使用缩进
来表示代码块,不需要使用大括号{}
缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数
python通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠 \
来实现多行语句
total = item_one + \
item_two + \
item_three
在[] {} ()中的多行语句,不需要使用反斜杠\
python中数字有四种类型:整数、布尔型、浮点数和复数
'
和双引号"
使用完全相同'''
或者”“”
)可以指定一个多行字符串tmp = “”“这是个多行字符串
这是个多行字符串”“”
\
print ('hello \nworld')
输出结果:hello world
print (r'hello \nworld')
输出结果:hello \nworld
+
运算符连接在一起,用*
运算符重复str='123456789'
print(str + ‘你好’) #连接字符串
print (str * 2) #输出字符串两次
0
开始,从右往左以-1
开始input( "请输入:\n" )