范雅惠python字串string方法methods

Python

荷蘭的電腦程式設計人員Guido Van Rossum 建立了Python。 Python 是一種廣泛使用的程式設計語言,用於 Web 應用程式、軟體開發、資料科學與機器學習 (ML)。開發人員使用 Python 的原因,在於 Python 效率高又容易學習,並且可以在許多不同的平台上執行。Python 軟體可以免費下載,與所有類型的系統完美整合,還可以加快開發速度。

VS Code與w3schools截圖

程式碼

txt = "hello范雅惠, and welcome to my world.ctrl+A"

x = txt.capitalize()

print (x)

print(txt.replace("雅惠","啞啞"))

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
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

评论

此博客中的热门博文

范雅惠Python自訂函數迴圈write模式a與w

范雅惠金融市場常識題庫158至170數學符號輸入Math公式