發表文章

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

張祐維開啟資料夾編寫檔案

圖片
space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input('輸入規格') m = input('輸入橫向規格') k,m=int(k),int(m) f = open("ˊ張祐維.txt",'w',encoding="utf8") 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): f.write(space) f.write(slash) for j in range(i-1): f.write(space) f.write(cr) f.close()

張祐維python檔案file方法methods

圖片
f = open("ascii.txt", "r") #註解開啟open檔案ascii.txt讀取模式r開啟之後要關閉 x = f.read() f.close() print("檔案長度", len(x)) print("列印內容",x)

張祐維python內建built-in函數function迴圈loop範圍range

w3schools內建函數列表   https://www.w3schools.com/python/python_ref_functions.asp 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 specified Unicode code. classmethod() Converts a method into a class method compile() Returns the specified source as an object, ready to be executed complex() Returns a complex number delattr() Deletes the specified attribute (property or method) from the specified object dict() Returns a dictionary (...