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

2018年11月12日 複習

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)