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")