First, the number int
used to calculate the number of bits that the number occupies in the binary form.
A = 9 # 9 binary is 1001b = a.bit_length ()print(b)
Results:
4
Second, String str
Converts a lowercase letter in a string to uppercase:
" ABCDE " = a.upper ()print(b)
The results are as follows:
ABCDE
lowercase letters in the string are converted:
" ABCDE " = a.lower ()print(b)
The results are as follows:
Abcde
Replace the specified character or string with the following:
" ABCDEDECDE " = a.replace ('cde'xue')Print (b)
The results are as follows:
Abxuedexue
"CDE" as the first parameter, is the replaced object, "Xue" as the second parameter, is the object that is substituted. The method also has a third parameter, which is the number of substitutions, and the default value is-1, which means replacing all matching characters (strings).
Finds the character or string specified in the string, returns the subscript of the first matching character (string), and returns 1 if it is not found:
" ABCDEDECDE " = a.find ('cde'= a.find ('z') Print (b) Print (c)
The results are as follows:
2-1
Eliminates substrings of strings and strings given in a string (no arguments are cleared for whitespace characters):
" CDABCDEDECDE " = A.strip ('cde')print(b)
The results are as follows:
Ab
Description: The substring of ' CDE ' is: ' CDE ', ' CD ', ' De ', ' C ', ' d ', ' e ', the Strip method matches the substring of ' CDE ' to the string object and, if successful, removes the substring. The end result is AB.
The string is sliced by the specified character (string), and the result returns a list:
" CDABCDEDECDE " = a.split ('cd')print(b)
Results:
["'ab''Ede'E ']
Inserts a character (string) between the characters of the specified string:
" CDABCDEDECDE " '_+_'. Join (a)print(b)
Results:
C_+_d_+_a_+_b_+_c_+_d_+_e_+_d_+_e_+_c_+_d_+_e
' _+_ ' is the inserted object, and the parameter of join () is the inserted object.
Iii. List of lists
Four, tuple tuple
V. Dictionary Dict VI, boolean bool
Python's basic data types and their common methods