VS Code開發環境w3schools截圖 程式碼 a = "Ha,陳麗慧很CUTE,很活潑!很有熱忱!我使用w3schools學習,也會使用vsCode開發環境" b = a.replace('活潑','熱忱') print (a) print (b) print ('幾個很?', a.count('很')) print ('很在0,1..位置', a.find('很')) print ('很在0,1..位置', a.rfind('很')) print ('a的長度',len(a)) print('英文大寫',a.upper()) print('英文小寫',a.lower()) txt = "HELLO,將第一個字母轉成大寫。" x = txt.capitalize() print (x) print (txt.casefold()) y = txt.center(30) print(txt.center(30)) print(y) print(len(y)) w3schools字串方法列表 https://www.w3schools.com/python/python_ref_string.asp 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 th...
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") 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('\n') f.close() 384教學影片
留言
張貼留言