資料型別轉換:Data_type_conversion
阿新 • • 發佈:2018-12-11
今日筆記:
# _author:VULCAN # date:2018/8/21 # int--->str # i = 1 # a = str(i) # print(a, type(a)) # str--->int str轉換為int時,str的資料得為數字 # x = "3678sdf" # x1 = "1542" # y = int(x1) # print(x1, type(x1)) # str--->bool,只要是空字串,轉換後就是False,只要字串是非空,轉換後就是True # x = "3678sdf" # x1 = bool(x) # y = "" # y1 = bool(y) # print(x1) # True # print(y1) # bool--->str 只要是True,轉換後就是非空字串,只要是False,轉換後就是空字串 # d = True # d1 = str(d) # print(d1, type(d1)) # f = False # f1 = str(f) # print(f1, type(f1)) # int--->bool 遵循非零即True原則 # a = 0 # aa = 1 # aaa = 199 # a1 = bool(a) # a2 = bool(aa) # a3 = bool(aaa) # print(a1) # print(a2) # print(a3) # bool--->int True--->1 False--->0 # t = True # t1 = int(t) # print(t1) # f = False # f1 = int(f) # print(f1) # while True:# True 需要先轉換為1,所以效率低 # pass # while 1: # 效率高於while True # pass