一、变量命名规则
1、字母、数字、下划线组成,且不能是数字开头。
2、Python关键字,也不能使用 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield
3、Python的内置函数或类最好也不要用。
二、注释
1、单行注释‘ #
2、多行注释 三引号(单双引号都可以)
# print('Hello World1')
"""
print('Hello World2')
print('Hello World2')
"""
'''
print('Hello World3')
print('Hello World3')
print('Hello World3')
'''
三、三种流程结构
1、顺序结构
从上到下顺序执行。
2、条件判断结构
(1)if-else
#没else分支
if True:
print('1')
#有else分支
if False:
print('2')
else:
print('3')
#支持嵌套
if True:
if True:
print('4')
else:
print('5')
else:
print('6')
(2)if elif
s = input('>>>')
if s == '1':
print('I am 1')
elif s == '2':
print('I am 2')
elif s == '3':
print('I am 3')
else:
print('others')
print('end')
补充,空白分支要写pass,不然会报错。
(3)and or not
and 且
or 或
not 非
if 1==1 and 1==2:
print('first')
elif 1==1 or 1==2:
print('secend')
if not 1==2:
print('ok')
3、循环结构
(1)while语句
#不带else
l = 0
while l < 4:
print(l)
l +=1
#带else
l=10
while l<4:
l += 1
else:
print(l)
(2)for语句
for 变量 in 可迭代对象:
for item in range(0,10,3):
print(item)