Capitalize the first letter of the capitalize string
name = 'xmzncc' v = name.capitalize() print(v)
casefold lowercase all capitals (supports multiple national languages)
name = 'Xmzncc' v = name.casefold() print(v)
lower converts capitals to lowercase (English only)
name = 'Xmzncc' v = name.lower() print(v)
center text centered
Parametric 1: Represents the total length
Parametric 2: Characters filled in the blank (length 1)
name = 'xmzncc' v = name.center(20,'*') print(v)
rjust,ljust fills around, including its own length
name = 'xmzncc' v = name.rjust(20,'*') print(v)
name = 'xmzncc' v = name.ljust(20,'*') print(v)
count denotes the number of times an incoming string appears
Parametric 1: The value to be looked up (subsequence)
Parametric 2: Starting position (index)
Parametric 3: End position (index)
name = 'asdasdjasdhaiuyeluqjh' v = name.count('as') print(v)
Does endswith end with xx
name = 'xmzncc' v = name.endswith('cc') print(v)
Does startswith Start with xx
name = 'xmzncc' v = name.startswith('xm') print(v)
Index finds the location of the specified subsequence index
name = 'xmzncc' v = name.index('c') print(v)
find finds the location of the specified subsequence index, does not return - 1, and does not report an error.
Unlike index, index cannot find an error
name = 'xmzncc' v = name.find('f') print(v)
format string formatting
tpl = 'I am:{0};Age{1};Gender{2}' v = tpl.format('fcc',18,'man') print(v)
Is isalnum/isalpha a Number or Chinese Character
name = 'xmzncc Pham Xuan Thanh' v = name.isalnum() print(v) v2 = name.isalpha() print(v2)
isdecima/isdigit/isnumeric to determine whether it is a number
isdecima can only judge Arabic numerals
isdigit can judge Arabic numerals, 2
isnumeric can judge Arabic numerals, 2 and 3
name = '2' v1 = name.isdecimal() print(v1) v2 = name.isdigit() print(v2) v3 = name.isnumeric() print(v3)
Is isidentifier an indicator
Except for built-in keywords
name = 'xmzncc' v = name.isidentifier() print(v)
Is islower all lowercase?
name ='Xmzncc' v = name.islower() print(v)
Is isupper all capitalized?
name = 'XMZNCC' v = name.isupper() print(v)
upper all capitalized
name = 'xmzncc' v = name.upper() print(v)
lower all lowercase
name = 'XMZNCC' v = name.lower() print(v)
Does isprintable contain implied xxx
If there is a return to False
name = 'asdasdadasd\tsadasd' v = name.isprintable() print(v)
Is isspace all blank?
name = ' ' v = name.isspace() print(v)
join element stitching string
name = 'xmzncc' v = '_'.join(name) print(v)
Translation Correspondence Re-translation
That is to say, find and replace
m = str.maketrans('asd','xxx') name = "123asd890" v = name.translate(m) print(v)
partition splits and retains the splitting elements
name = 'xmzncc000fcc' v = name.partition('000') print(v)
replace substitution
Settable Index Location
name = 'xmzncc000fcc000asdasd' v = name.replace('000','111',1) print(v)
strip removes blanks
name = 'xmzncc\n' v = name.strip() print(v)
swapcase case case-to-case conversion
name = 'XMznCC' v = name.swapcase() print(v)
zfill fill0
name = 'xmzncc' v = name.zfill(20) print(v)
Summary of string functions:
name.upper() name.lower() name.split() name.find() name.strip() name.startswith() name.format() name.replace() "xmzncc".join(["as",'bb'])
Additional functions:
name[0] name[0:3] name[0:3:2] len(name) for Loop, each element is a character