發表文章

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

賴昀威Python字串string方法methods

圖片
單元371影片 vs code與w3schools截圖 程式碼 txt = "香蕉" x = txt.center(20) print(x) txt = "賴昀威 love 香蕉, 香蕉是我 favorite 水果香蕉" print(txt.count("香蕉")) print('先練習內建函數len',len(txt)) print('find',txt.find("香蕉")) print('rfind',txt.rfind("香蕉")) print('index',txt.index("香蕉")) w3school自串方法列表 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 and returns the position of where it was found format() Formats specified values in a string format_map() Formats specified values in a string index() Searches the string for a specified value ...