Python basics 3 -- string, python3 -- string
String
1. case-insensitive Conversion
1 >>> name 2 'bigint' 3 >>> name. capitalize () # capital 4 'bigberg '5 >>> name 6 'bigberg' 7 >>> name. casefold () # Replace all uppercase characters with lowercase 8 'bigberg '9 10 >>> name. upper () # All characters are capitalized 11 'bigint' 12 >>> name. lower () # All characters in lower case 13 'bigberg'
2.
1 'bigberg '2> name. center (20, '-') # center, 20 characters long 3 '------ bigberg ------- '4 5 >>> name. find ('B') # search for characters. If the index exists, the first index is returned. If the index does not exist, the system returns-1 6-1 7 >>> name. find ('B') 8 0 9 >>> name. find ('G') 10 211 12 >>> name. endswith ('sd') # character 13 False14 at the end of the query> name. endswith ('G') 15 True
3. Determine the string type
1 >>> name. isalpha () # whether it is a string 2 True 3 >>> name 4 'bigberg '5 >>>. isalpha () 6 False 7 >>> a 8 '000000' 9 >>>. isdigit () # whether it is an integer 10 True11 >>>. isnumeric () # whether all are numbers 12 True13 14 isspace # whether it is a space 15 is. upper () # whether it is all uppercase 16 is. lower () # whether it is all lowercase 17 18 >>> name # convert all uppercase and lowercase 19 'bigberg '20 >>> name. swapcase () 21 'bigberg'
4. join ()
1 >>> "-".join(['123','456','789'])2 '123-456-789'