b = "我男友是個大帥哥" #python字串單或雙引號都可 # 0 1 2 3 4 # -6-5-4-3-2-1 print("字串長度:"+str(len(b)))#相同字串型態才能串接 print("反過來:"+b[::-1]) print(b[:3]) #b字串的0,1,2 print(b[-4:-1]) print(b[-8:-4]) x='火鍋' y=9999 myorder="我希望{2}陪我去吃{0}他付錢{1}." print(myorder.format(x, y, b)) # format的參數 0 1 2 字串的方法列表 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 and returns the position...
留言
張貼留言