while 循环 break continue
if in
记得用tab键退格
%s 字符串占位符
%d 数字占位符
print("%s今年%s岁,是一个老头,爱好是%s,性别:%s" % (name,age,hobby,gender))
如果字符串中使用了 %s %d 等占位符(字符串后面当然要配合 % 及数字列表使用),则其他的 % 也会被认为是占位符,如果要正确输出 % ,需要使用 %% 转义输出为 %
and or not 同时存在,先算括号,然后算not 再算and 最后算 or
and or 为判断布尔值(真假)运算符,数字0为FALSE,非0整数为TRUE。
0 and 8 ==0, 3 and 8== 8 , 3 and 0 == 0, 0 and 0 == 0
0 or 8 ==8 , 3 or 8 == 3 3 or 0 == 3 , 0 or 0 == 0
while 可跟 else 搭配使用
count = 1
while count <= 10:
print(count)
count = count+1
if count == 5:
break #停止循环,不会执行后面的else
else:
print("这里是else")