a.capitalize() title case
a.casefold() All lowercase
a.lower() All lowercase
a.upper() All variable capitals
a.swapcase() Size swap
a.title() The first word of each word is capitalized
a.center(50,'-') Fill left and right
a='jJak\ti' a.expandtabs(20) contain \t String specifying how many spaces
a.ljust(20,'*') Add on the right 20 individual * Number
a.rjust(20,'*') Left supplement 20 individual * Number
a.zfill(20) Insufficient string 20 Bit added on the left 0, Added to 20 position
a.strip() Remove the space on the left and right ,\n \t
a.ltrip() Remove the space on the left side ,\n \t
a.rtrip() Remove the space on the right side ,\n \t
a='abcd
a.startswith('A') With A start , Case sensitive
a.endswith('d')
a.isdigit() Integers , return true
a.isalpha() Letter ( Including Chinese ), return true
a.isalnum() Letter ( Including Chinese ) Or digital , return true
a.islower() Judge whether all are lowercase
a.isupper() Determine whether all are capitalized
a.istitle() Determine whether the first word of each word is capitalized
a='ABCDEFG'
a.find('G') Left to right , find G, Return subscript value , No return found -1
a.find('G',4,20) From 4 Digits to 20 digit , find G, Return subscript value , No return found -1
a.rfind('G') From right to left , find G, Return subscript value , No return found -1
a.index similar find, But if you can't find it, you will report an error
a.count Usage is similar. , Count the number of strings that appear
a.split('D',1) , The default is to cut with spaces , Returns a list of , The number indicates the number of cuts
a.rsplit Cut from the left
a.removeprefix('A') Remove the prefix
a.removesuffix('A') Remove the suffix
a.replace('D','F',1) D Switch to F, Just change it once , If it is not filled in, the default is to replace all
a=['A','b','c']
'-'.join(a) use “-” String concatenation , return :A-b-c, Variable a, Can be a string , Tuples , list
aa=' One, two, three '
print(list(reversed(aa)))
print(aa[::-1],type(aa[::-1]))
aa=(' first place ',' Second ',' Third ')
print(tuple(reversed(aa)))
aa=[' first place ',' Second ',' Third ']
print(list(reversed(aa)))
Be careful :reversed() Function returns an iterator , Support string , Tuples , list ,
Return an object ,, So we need to list/tuple Function to convert the corresponding data type
Return results :
[' 3、 ... and ', ' Two ', ' One ']
Three, two, one <class 'str'>
(' Third ', ' Second ', ' first place ')
[' Third ', ' Second ', ' first place ']
Python One click to collect al
Python describe LeetCode 515.