劉任昌Python字串string方法methods

VS Code與w3schools截圖

程式碼

txt = "hello劉任昌, and welcome to my world.ctrl+A"
x = txt.capitalize()
print (x)
print(txt.replace("任昌", "總統"))
print("and位置",txt.find("and"))
a = "Ha,蔡英文很Handsome,很變態!很詭異!我使用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 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 of where it was found isalnum() Returns True if all characters in the string are alphanumeric isalpha() Returns True if all characters in the string are in the alphabet isascii() Returns True if all characters in the string are ascii characters isdecimal() Returns True if all characters in the string are decimals isdigit() Returns True if all characters in the string are digits isidentifier() Returns True if the string is an identifier islower() Returns True if all characters in the string are lower case isnumeric() Returns True if all characters in the string are numeric isprintable() Returns True if all characters in the string are printable isspace() Returns True if all characters in the string are whitespaces istitle() Returns True if the string follows the rules of a title isupper() Returns True if all characters in the string are upper case join() Converts the elements of an iterable into a string ljust() Returns a left justified version of the string lower() Converts a string into lower case lstrip() Returns a left trim version of the string maketrans() Returns a translation table to be used in translations partition() Returns a tuple where the string is parted into three parts replace() Returns a string where a specified value is replaced with a specified value rfind() Searches the string for a specified value and returns the last position of where it was found rindex() Searches the string for a specified value and returns the last position of where it was found rjust() Returns a right justified version of the string rpartition() Returns a tuple where the string is parted into three parts rsplit() Splits the string at the specified separator, and returns a list rstrip() Returns a right trim version of the string split() Splits the string at the specified separator, and returns a list splitlines() Splits the string at line breaks and returns a list startswith() Returns true if the string starts with the specified value strip() Returns a trimmed version of the string swapcase() Swaps cases, lower case becomes upper case and vice versa title() Converts the first character of each word to upper case translate() Returns a translated string upper() Converts a string into upper case zfill() Fills the string with a specified number of 0 values at the beginning
MethodDescription
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 of where it was found
isalnum()Returns True if all characters in the string are alphanumeric
isalpha()Returns True if all characters in the string are in the alphabet
isascii()Returns True if all characters in the string are ascii characters
isdecimal()Returns True if all characters in the string are decimals
isdigit()Returns True if all characters in the string are digits
isidentifier()Returns True if the string is an identifier
islower()Returns True if all characters in the string are lower case
isnumeric()Returns True if all characters in the string are numeric
isprintable()Returns True if all characters in the string are printable
isspace()Returns True if all characters in the string are whitespaces
istitle()Returns True if the string follows the rules of a title
isupper()Returns True if all characters in the string are upper case
join()Converts the elements of an iterable into a string
ljust()Returns a left justified version of the string
lower()Converts a string into lower case
lstrip()Returns a left trim version of the string
maketrans()Returns a translation table to be used in translations
partition()Returns a tuple where the string is parted into three parts
replace()Returns a string where a specified value is replaced with a specified value
rfind()Searches the string for a specified value and returns the last position of where it was found
rindex()Searches the string for a specified value and returns the last position of where it was found
rjust()Returns a right justified version of the string
rpartition()Returns a tuple where the string is parted into three parts
rsplit()Splits the string at the specified separator, and returns a list
rstrip()Returns a right trim version of the string
split()Splits the string at the specified separator, and returns a list
splitlines()Splits the string at line breaks and returns a list
startswith()Returns true if the string starts with the specified value
strip()Returns a trimmed version of the string
swapcase()Swaps cases, lower case becomes upper case and vice versa
title()Converts the first character of each word to upper case
translate()Returns a translated string
upper()Converts a string into upper case
zfill()Fills the string with a specified number of 0 values at the beginning

留言

  1. https://the-dumbest-one.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  2. https://huilii.blogspot.com/2024/02/a-hacutew3schoolsvscode-b-a_28.html

    回覆刪除
  3. https://hsiao-yu0711.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  4. https://fanyahui.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  5. https://manranwen.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  6. https://euhffh822.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  7. https://www.blogger.com/blog/post/edit/preview/9196338979477839802/1299107537441768196

    回覆刪除
  8. https://sushshshaq119.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  9. https://www.blogger.com/blog/post/edit/preview/140343921285915300/2743665727055595356

    回覆刪除
  10. https://meimei20041026.blogspot.com/2024/02/pythonstringbuilt-inmethods.html

    回覆刪除
  11. https://kai2424.blogspot.com/2024/02/pythonstringbuilt-inmethods.html

    回覆刪除
  12. https://the-most-great-tony11.blogspot.com/2024/02/vs-codew3schools.html

    回覆刪除
  13. https://the-most-beautifui666.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  14. https://ehiwkewh.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  15. https://ccp19890604.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  16. https://earnest-person.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  17. https://michelle814.blogspot.com/2024/02/pythonstringbuilt-inmethods.html

    回覆刪除
  18. https://huang-pei-kai.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  19. 作者已經移除這則留言。

    回覆刪除
  20. 作者已經移除這則留言。

    回覆刪除
  21. https://ruubyy0.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  22. https://the-most-great.blogspot.com/2024/02/python.html

    回覆刪除
  23. https://www.blogger.com/blog/post/edit/preview/2975575936248622997/2533591242064477068

    回覆刪除
  24. https://imyuannn.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  25. https://supocheng25.blogspot.com/2024/02/pythonstringbuilt-inmethods.html

    回覆刪除
  26. https://zheng-fu-zhe.blogspot.com/2024/02/txt-hello-and-welcome-to-my-world.html

    回覆刪除
  27. https://s10655075.blogspot.com/2024/02/vs-codew3schools.html

    回覆刪除
  28. https://the-most-great-chenxi.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  29. https://www.blogger.com/blog/post/edit/preview/7605861353123298610/3970939738446444527

    回覆刪除
  30. https://chyuu126.blogspot.com/2024/02/pythonstringmethods.html

    回覆刪除
  31. https://honghikun.blogspot.com/2024/02/pythonstringbuilt-inmethods.html

    回覆刪除
  32. https://0209tongting.blogspot.com/2024/03/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌大語言模型協助收集簡報的資料

劉任昌w3schools學習ASCII, Emoji與Javascript迴圈

劉任昌HTML,CSS,樣式style,嵌入iframe