1.type: View the current type of string
1 c='123' 2 print(type(c),c) 3 b= int(c) 4 print(type(b),b) 5 6 num="01010" 7 a=int(num,base=16) 8 print(a) 9 10 >><class 'str'> 123 11 >><class 'int'> 123
2.bit_length: View the current system of how many secondary figures
1 a=10 2 v=a.bit_length() 3 print(v) 4 5 >>4
3.capitalize: The first letter capitalized
1 test="aLse" 2 v=test.capitalize() 3 print(v) 4 5 >>Alse
4. (casefold, lower): all letters to lower case, casefold enable more unknown strain lowercase
1 test="ASD" 2 v1=test.casefold() 3 print(v1) 4 v2=test.lower() 5 print(v2)
5.swapcase: uppercase conversion
1 test="alex" 2 v=test.swapcase() 3 print(v)
6.center: set the width and center the contents
1 # * Blank filled unknown 2 Test = " ASD " . 3 V = test.center (20 is) # 20 is to refer to the length . 4 V1 = test.center (20 is, " . 9 " ) . 5 Print (V, V1)
1 >> 99999999asd999999999 by asd
7. (ljust (left), the rjust (Right)): arbitrarily specified width, fill character
1 test="asd" 2 v=test.ljust(20,"%") 3 v1=test.rjust(20,"%") 4 print(v) 5 print(v1) 6 7 >>asd%%%%%%%%%%%%%%%%% 8 >>%%%%%%%%%%%%%%%%%asd
8.zfill: String filling, you can not specify a character to fill
1 test="123" 2 v=test.zfill(20) 3 print(v)
1 >>00000000000000000123
9.counter: to find a string of number sequences appear
. 1 Test = " alasddslaw " 2 V = test.count ( " A " ) . 3 V1 = test.count ( ' SD ' ) . 4 V2 = test.count ( ' A ' , 5) # denotes the fifth from the beginning to find 5 test.count = V3 ( ' A ' , 5,6) # indicates start looking from the fifth to the sixth end . 6 Print (V, V1, V2, V3) . 7 . 8 >> 0. 3. 1. 1
10. (endswith, startswith): Analyzing fixed end \ Start
1 test="abc" 2 v=test.endswith('c') 3 v=test.startswith('a') 4 print(v) 5 6 >>True
11.expendtabs: punctuation
1 test='username\temail\tpassword\nxiaozhou\[email protected]\t123\nxiaoli\[email protected]\t345\nxiaowang\[email protected]\t789\n' 2 v=test.expandtabs(20) 3 print(v) 4 5 >> 6 username email password 7 xiaozhou [email protected] 123 8 xiaoli [email protected] 345 9 xiaowang [email protected] 789
12. The split only according to: confirm whether to keep wrap true, false \ n
1 test="assdsfdg\nsjfdhsdef\nksf" 2 v1=test.splitlines(False) 3 v2=test.splitlines(True) 4 print(v1) 5 print(v2) 6 7 >>['assdsfdg', 'sjfdhsdef', 'ksf'] 8 >>['assdsfdg\n', 'sjfdhsdef\n', 'ksf']
13.find: look for strings, output -1 not found
. 1 Test = " alexalex " 2 # if not found, the output: -1 . 3 V = test.find ( ' X ' ) . 4 Print (V) . 5 . 6 >>. 3
14.index: index, an error can not find it
1 test="qwert" 2 v=test.index('q') 3 print(v) 4 5 >>0
15.format: formatting a string placeholder with the value specified
1 test='i am {name},age{a}' 2 v=test.format(name='xiaowang' ,a='18') 3 print(v) 4 5 >>i am xiaowang,age18
16.isalnum: string contains only letters and numbers
1 test="123" 2 v=test.isalnum() 3 print(v) 4 5 >>True
17.isidentifier: Analyzing letters, underline, identifier
1 a="def" 2 v=a.isidentifier() 3 print(v) 4 5 >>True
18. (isdecimal, isdigit, isnumeric): determining whether a digital
1 Test = INPUT ( ' Please Enter STR or int: ' ) # example: 1, two 2 V1 = test.isdecimal () . 3 V2 = test.isdigit () . 4 V3 = test.isnumeric () # support Chinese figures . 5 Print (v1, v2, v3)
19.keyword Module: Displays the current version all keywords
. 1 Import keyword 2 keyword.kwlist # output command window
20.isprintable: determining whether the character is not displayed or can not output, \ T tab, \ n-newline
1 test="asdfghj" 2 v=test.isprintable() 3 print(v) 4 5 >>True
If inadequate, please correct me!