输出
print("hello")
print('hello')
输入
a = input("please something: ")
print(a)
将会打印你所输入的东西
if语句
if condition1:
statement_block1
elif condition2:
statement_block2
else:
statement_block3
for语句
for循环基本结构(常用于遍历)
for <variable> in <sequence>:
statement_block1
else:
statement_block2
range函数(用于遍历数字序列)
#打印0-4
for i in range(5):
print(i)
range设置步长
range(0, 10, 3),打印0-9中的数字,3为步长,即打印0,3,6,9
while语句
while基本语句结构
while condition:
statement_block
while-else语句
while condition:
statement_block1
else:
statement_block2