1. 程式人生 > >day12-2018-11-2 內建函式

day12-2018-11-2 內建函式

lst = ["唐伯虎", "小娟", "張鶴倫", "燒餅"]

# it = lst.__iter__()
# print(it.__next__())
# print(it.__next__())
# print(it.__next__())
# print(it.__next__())


# it = iter(lst) # 獲取迭代器
# print(it.__next__())
# print(next(it)) # 相當於 __next__()
# print(next(it))
# print(next(it))

# s = "胡辣湯"
# print(id(s)) # 2175466552560  記憶體地址的int形式
# print(hash(s)) # 唯一的數字, 為了儲存 6492443426362943124 8426701594033488624 # print(hash(s)) # # print(hash(13)) # 數字的雜湊值就是它本身 # 4342805289873345757 雜湊值不能做密碼-> md5 # 4342805289873345757 # 4931740966047962723 # 4931740966047962723 # print(help(str)) # 幫我看看str是啥 # a = 10 # # a() # 不可以被呼叫 () # # def chi():
# print("吃什麼呢") # # chi() # # print(callable(a)) # False # print(callable(chi)) # True # def dai(fn): # if callable(fn): # 判斷引數是否可以被呼叫 # fn() # else: # print("不能被呼叫") # # dai(10) # print(dir(str)) # 255 255 255 255 # 11111111 11111111 11111111 11111111 # print(bin(256)) # 0b100 1 10 11 100
# print(oct(8)) # 0o10 # print(hex(15)) # 十六進位制-> 0-9 abcdef # print(int(0x10)) # 十進位制 # float 浮點數 # print(type(0.0112)) # complex 複數 = 實數+虛數 # 實數: 有理數+無理數(無限不迴圈小數 pi) # i ** 2 = -1 虛無縹緲的數 # matlab # print(abs(3)) # 絕對值. 取模 # # print(divmod(20, 555555555555)) # 不太好用. # print(round(4.4)) # 如果整數位是偶數靠近偶數進行捨棄 - # print(round(5.4)) # 如果整數位是偶數靠近偶數進行捨棄 + # 自定義的 # def func(num): # "5.4123456" ["5", "4123456"] # fu = 1 # if num < 0: # fu = -1 # # num = abs(num) # snum = str(num) # if int(snum.split(".")[1][0])>=5: # 入 # return (int(snum.split(".")[0])+1)*fu # else: # 舍 # return int(snum.split(".")[0])*fu # # print(func(11.99)) # print(pow(10,2,3)) # print(10**2) # 1+2+3+4+5+6+7...100 # print(sum(range(101))) # range(101) 可迭代物件 # sum(可迭代物件) # print(max(1,2,3,-4,5,6,7,8,9)) # print(min(1,2,3,-4,5,6,7,8,9)) # lst = ["哈哈", "呵呵", "吼吼"] # for i in range(len(lst)): # print(i) # print(lst[i]) # for i,el in enumerate(lst, 100): # (索引, 元素) # print(i, el) # lst = ["電腦", "鍵盤", "滑鼠"] # for i, el in enumerate(lst, 1): # print(i, el) # print(all([1,2,True,0])) # False and # print(any([1,'',0])) # True or # zip 拉鍊函式 # lst1 = ["胡歌", "霍建華", "彭于晏", "吳彥祖"] # lst2 = [37,46,50] # lst3 = ["仙劍三", "花千骨", "湄公河行動", "警察故事"] # # z = zip(lst1, lst2, lst3) # 第0個放一起, 第一個放一起, 第二個放一起. 水桶效應 # print("__iter__" in dir(z)) # 可以迭代 # for el in z: # print(el) # lst = (1,2,3,4,5) # new_lst = reversed(lst) # 通用 # for el in new_lst: # print(el) # s = "哈哈哈哈" # for c in s: # print(c) # # lst = {1,2,3,4,5} # for c in lst: # print(c) # st = "⼤家好, 我是麻花藤" # s = slice(1, 6, 2) # print(st[s]) # st[::] # lst1 = [1,2,3,4,5,6,7,8,9] # lst2 = [1,2,3,4,5,6,7,8,9] # lst3 = [1,2,3,4,5,6,7,8,9] # lst4 = [1,2,3,4,5,6,7,8,9] # lst5 = [1,2,3,4,5,6,7,8,9] # lst6 = [1,2,3,4,5,6,7,8,9] # lst7 = [1,2,3,4,5,6,7,8,9] # lst8 = [1,2,3,4,5,6,7,8,9] # lst9 = [1,2,3,4,5,6,7,8,9] # lst10 = [1,2,3,4,5,6,7,8,9] # lst1[s] # lst1[s] # lst1[s] # lst1[s] # lst1[s] # lst1[s] # lst1[s] # lst1[s] # 字串 # print(format('test', '<20')) # 左對⻬ cener(20) # print(format('test', '>20')) # 右對⻬ # print(format('test', '^20')) # 居中 # # 數值 # print(format(3, 'b')) # ⼆進位制 11 # print(format(97, 'c')) # 轉換成unicode字元 a # print(format(11, 'd')) # ⼗進位制 11 # print(format(11, 'o')) # ⼋進位制 13 # print(format(11, 'x')) # ⼗六進位制(⼩寫字⺟) b # print(format(11, 'X')) # ⼗六進位制(⼤寫字⺟) B # print(format(11, 'n')) # 和d⼀樣 11 # print(format(11)) # 和d⼀樣 11 # # 浮點數 # print(format(123456789, 'e')) # 科學計數法. 預設保留6位⼩數 # print(format(123456789, '0.2e')) # 科學計數法. 保留2位⼩數(⼩寫) # print(format(123456789, '0.2E')) # 科學計數法. 保留2位⼩數(⼤寫) # print(format(1.23456789, 'f')) # ⼩數點計數法. 保留6位⼩數 # print(format(1.23456789, '0.2f')) # ⼩數點計數法. 保留2位⼩數 # print(format(1.23456789, '0.10f')) # ⼩數點計數法. 保留10位⼩數 # print(format(1.23456789e+10000, 'F')) # ⼩數點計數法. INF 無窮 # 1.2508132548754585 # print(format(1.2508132548754585,"0.2f")) # s = "今天星期五" # print(s.encode("utf-8")) # print(bytes(s, encoding="utf-8")) # 網路通訊要用到它 # s = "記憶體" # m = memoryview(s.encode("utf-8")) # 不給程式設計師用的 # print(m) # print(ord("中")) # 檢視編碼位置 # # print(chr(20013)) # 檢視某位置的編碼是誰 # for i in range(65536): # print(chr(i), end=" ") # print(ascii("中國韓國日本新加坡")) # 判斷你的文字是否在ascii裡面. 也能獲取到unicode # 在字串中使用\表示的轉義 # \n 換行 \t製表符 \r回車 # \\ \ # \" " # \' ' # # python使用的字串實際上和c的字串是不一樣的. python對字串進行了處理 # print("你好我叫\\劉德\n華我叫周潤發") # # 字串最應該顯示的樣子. 最底層, 最官方的顯示效果 # print(repr("你好我叫\\劉德\n華我叫周潤發")) # __repr__ __str___ # print(r"你給我顯\示一下\n") # r"" 原樣輸出 # print(r"\/\d+\w|\d?*") # name = "胡辣湯" # # 3.6以上 # print(f"我想吃{name}") # f format {佔位賦值} # # print("我想吃%s" % name) # code = "1+2+3+5" # ret = eval(code) # 直接執行字串型別的程式碼. 有返回值 # print(ret) # code = "n = 16" # exec(code) # print(n) # 16 # code = input("請輸入你要執行的程式碼") # exec(code) # 執行程式碼. 沒有返回值 # exec和eval 都不可以一次性執行大段的程式碼(字串). # code="1+2+3+4+5" # c = compile(code, "", mode="eval") # print(eval(c)) # code = """ # for i in range(10): # print(i) # for j in range(10): # print(j) # """ # c = compile(code, "", mode="exec") # exec(c) # 執行程式碼 # code = """name = input('請輸入你的名字')""" # c = compile(code, "", mode="single") # single 有互動 # exec(c) # print(name) # pycharm的提示有的時候是不對的 # 可以把字串型別的資料轉化成具體的某些資料 # qianduan = "[1,2,3,4,5]" # json # lst = eval(qianduan) # print(lst) # 列表