發表文章

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

黃郁庭phthon自訂函數迴圈範圍range寫入模式a,x,w,r

圖片
期中考複習拷貝撰寫模式 write寫入檔案模式mode w=write會覆蓋原有檔案, a=append接續原來檔案, x=create創立新檔案, x與w有何不同? write寫入檔案,預設不換行,換行'\n' print呈現在螢幕,預設換行,不換行end=''。 write寫入用到英文以外的字元(一,a,b)encoding='utf8' 期中考複習拷貝撰寫模式 write寫入檔案模式mode w=write會覆蓋原有檔案, a=append接續原來檔案, x=create創立新檔案, x與w有何不同? write寫入檔案,預設不換行,換行'\n' print呈現在螢幕,預設換行,不換行end=''。 write寫入用到英文以外的字元(一,a,b)encoding='utf8' 387

黃郁庭phthon寫入write迴圈範圍range

圖片
space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input('邊長: ') #輸入字串 m = input('橫向: ') k, m = int(k), int(m) f = open("黃郁庭.txt",'w',encoding='utf8') f.write('黃郁庭讀取檔案' + cr)#註解\n換列 for i in range(9): f.write(str(i)) f.write(cr) for i in range(1, k+1): #迴圈1到k 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): f.write(space) f.write(slash) for j in range(i-1): f.write(space) f.write(cr) f.close()

黃郁庭python檔案方法utf8

圖片
f = open("ascii.txt", "r",encoding='utf8') print(f.read()) f.close() x = "黃郁庭" f = open("ascii.txt", "r+",encoding='utf8') y = f.write(x) print(y) f.close() print(i) f = open("ascii.txt", "r+",encoding='utf8') #a代表附加append print("名稱",f.name) print("模式",f.mode) print("關閉",f.closed) f.write('黃郁庭') line = f.read() #讀取檔案f成為字串 print('檔案字串長度',len(line)) print("檔案內容",line) f.close() 影片379 影片380

黃郁庭python內建built-in函數functions迴圈loop

圖片
截圖 程式碼 print(int(10)) print(int('ff' ,16)) print(int('100' ,16)) print(int('100' ,8)) a = [0>1, 2>1, 3==3]#串列list使用square bracket中括號 print("是否all全真",all(a)) print("存在任何any一個真" ,any(a)) print("黃郁庭bin二進位輸出一到9") for i in range(10): #0 to 9進位1 print(bin(i)) for i in range(0, 200, 10): print(hex(i)) w3schools內建函數列表 Python has a set of built-in functions. 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...

黃郁庭Python字串string方法methods

圖片
單元371影片 vs code與w3schools截圖 程式碼 txt = "黃郁庭Love木瓜,木瓜我my favoritE水果木瓜" print(txt.count("木瓜")) print('先練習內建函數len',len(txt)) print('find',txt.find("木瓜")) print('rfind',txt.rfind("木瓜")) print("print列印,字串string字元character的組合") print(txt.title()) print(txt.lower()) print(txt.upper()) print(txt.swapcase()) print(txt.zfill(32)) print(txt.startswith("黃")) print(len(txt)) for i in range(33333, 33344): print(chr(i)) for i in range(65, 70): print(chr(i)) w3schools字串方法列表 Method Description capitalize() Converts the first character to upper case casefold() Converts string into lower case center() Returns a centered string count() Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value expandtabs() Sets the tab size of the string find() Searches the string for a specified value ...