a = 2
b = 1
if a > b:
print(a)
else:
print(b)
多个if语句
a = 2
b = 1
if a > b:
print(a)
elif a == b:
print(b)
elif a < b:
print(a)
三元表达式
print(a if a > b else b) #打印a如果a大于b的话,否则打印b
有2种方式,for x in list,tutle,另一种是while循环
打印1到100的整数和
sum = 0
for i in range(1, 101):
sum += i
print(sum)
sum = 0
i = 0
while i < 101:
sum += i
i += 1
print(sum)
break和continue,break是跳出当前循环,而continue是跳过本次循环,开启下一次循环
sum = 0
i = 0
while i < 101:
if i % 2 == 0: #跳过偶数,求出奇数和
i += 1
continue
else:
sum += i
i += 1
print(sum)
sum = 0
i = 0
while i < 101:
if i % 2 == 0:
i += 1
break
else:
sum += i
i += 1
print("i的值为:", i) #最后i的值是1
print(sum)
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款