1. 程式人生 > >2018年11月12日 復習

2018年11月12日 復習

數字 ctp ont bubuko while 循環 使用 n) 三次 子序列

utf-8,unicode,GBK 的差異----沒聽懂

中文字節 utf8:3個;gbk:2個

三次登入作業 方法2:

n=1
actname="sxj"
actpwd="123"
while True:
    name=input("name:")
    mima=input("mima:")
    n=n+1
    if actname==name and actpwd==mima:
        print("ok")
        break
    elif n>3:
        exit()

如果將字符串轉換成數字 new_inp= int

(inp)

while……else……語句

n=0
while n<5:
    print (n)
    n+=1
else:
    print ("TKS")

while 循環 else不循環

基本運算符 in 與 not in 檢查是否在裏面,快捷鍵ctrl+? 統一註釋

name= "sxj"
if "sx" in name :  #檢查sx是否在 sxj 的字符串中,sx這種字符串稱作為 子序列 或者 子字符串
    print("OK")
else:
    print ("Nok")
name= "sxj"
if "sx" not in name :  #檢查sx是否
在 sxj 的字符串中
print("OK") else: print ("Nok")

布爾值 True與 False

v= "s"in "sxj"  #結果反饋為布爾值 
if v:   
    print(v)  
else:
    print("s")

不等於號 != 或者<>;

技術分享圖片

運算順序

u= not 2==2  and 3>=2 or 4<=3 #從前到後,True 後面是or,則肯定為T,如果F 後面是and,
則為F,不往後計算了,推薦使用括號,先計算括號內的
print (u)

2018年11月12日 復習