發表文章

目前顯示的是 3月, 2024的文章

李政翰python寫入write讀出read文字檔

圖片
VS code開發環境截圖 程式碼 space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input('輸入三角形的邊長: ') m = input('輸入橫向規模: ') k, m = int(k), int(m) #將字串k轉integer f = open("李政翰.txt",'w',encoding="utf8") handsome = 'huginn hrafn'+cr f.write(handsome) for i in range(1, k+1):     for ii in range(m):         for j in range(k-i):             f.write(space)         f.write(slash)         for j in range(2*i-2):             f.write(space)         f.write(backslash)         for j in range(k-i):             f.write(space)     f.write(cr) for i in range(1, k+1):     for ii in range(m):         for j in range(i-1):             f.write(space)         f.write(backslash)         for j in range(2*k-2*i): ...

李政翰python檔案file方法methods

圖片
UTF8 encoding編碼 練習程式碼 f = open("ascii.txt", "r+", encoding='utf8') x = f.read() print(x) f.write("\n李政翰") #寫入字串 f.close() #李政翰關閉檔案 print('f長度',len(x)) for i in x: #用迴圈印出每一個字元 print(i) 影片377 影片378 ascii art字元藝術

李政翰python內建built-in函數function迴圈loop範圍range

圖片
style指令原始碼 <style>h1{text-align:center; background-color:blue; color: white;  border: solid medium blue; padding 10px;}   </style> vscord與w3school截圖 y = 0 for a in range(10,99,5): y = y+1 print("第幾", y, "次") print(a) #前面縮排同一個區塊 w3school內建函數列表 Function Description abs() Returns the absolute value of a number all() Returns True if all items in an iterable object are true any() Returns True if any item in an iterable object is true ascii() Returns a readable version of an object. Replaces none-ascii characters with escape character bin() Returns the binary version of a number bool() Returns the boolean value of the specified object bytearray() Returns an array of bytes bytes() Returns a bytes object callable() Returns True if the specified object is callable, otherwise False chr() Returns a character from the specified Unicode code. classmethod() Converts a method into a class method compile() Returns the specified source as an object, ready ...