String method:
The string is an ordered, non-modifiable, element that is surrounded by quotation marks. Single quotes, double quotes, triple quotes, str generation
string retouching a= ' Novo gene '
A.center () |
Centers the string at the specified length and, if not centered, fills it with spaces by default |
-a.center (20, ' * ') returns an original string centered and uses ' * ' to fill a new string of length 20 |
A.ljust () |
Leave the string aligned to the left, padding with spaces by default |
|
A.rjust () |
Aligns strings to the right, with spaces filled by default |
|
A.zfill () |
Fills the string to the specified length , with 0 padding in the insufficient place |
|
A.format () |
In order, the following arguments are passed to the preceding curly braces |
|
A.strip () |
By default, the whitespace is removed and the content can be specified |
-a.lstrip (' * ') |
A.rstrip () |
By default, the right space is removed and the content can be specified |
–a.rstrip (' * ') |
A.lstrip () |
The left space is removed by default, and the content can be specified |
–a.strip (' * ') remove both sides of the ' * ' |
Search for Strings:
A.count () |
Count function, returns the number of characters specified in the string |
–a.count (' O ') returns the number of occurrences of ' o ' in a |
A.find () |
Find, returns the index of the first specified character from left to right, cannot find return-1 |
–a.find (' G ') returns the first occurrence of ' g ' subscript, otherwise returns-1 |
A.rfind () |
Find, returns the index of the first specified character from right to left, cannot find return-1 |
|
A.index () |
Find, returns the index of the first specified character from left to right, no error found |
–a.index (' g ') otherwise returns an exception |
A.rindex () |
Find, returns the index of the first specified character from right to left, error not found |
|
Substitution of strings:
A.replace () |
Replace the specified element from left to right , you can specify the number of replacements, the default is replace all |
–a.replace (' O ', ' a ', 2) Replace the first 2 ' O ' with ' a ' |
A.translate () |
Replace the content according to the corresponding relationship (import module from string import Maketrans) |
|
Transformation of the string:
A.upper () |
converts all letters in a string to uppercase |
|
A.lower () |
converts all letters in a string to lowercase |
|
A.swapcase () |
swaps All letters in a string |
|
A.title () |
Capitalize the first letter of a word in a string, separated by a non-alphabetic word |
–a.title () capitalize the first letter of each word |
A.capitalize () |
capitalize the first letter of a string |
–a.capitalize () capitalizes the first character of a string |
A.expandtabs () |
Modify the default length of \ t |
|
The judgment of the string:
A.isalnum () |
Determines whether a string is completely composed of numbers and letters |
|
Isalpha |
Determines whether a string is entirely composed of letters |
–a.isalpha () returns True if a has at least one character and all characters are letters, otherwise False |
IsDigit |
Determines whether a string is completely composed of numbers |
–a.isdigit () returns True if the string contains only a number or False |
Isupper |
Determines whether a string is completely uppercase |
–a.upper () returns a string with all uppercase letters |
Islower |
Determines whether a string is completely lowercase |
–a.lower () returns a string of all lowercase letters |
Isspace |
Determines whether a string consists entirely of spaces |
|
StartsWith |
Judging the beginning character of a string, you can intercept the judgment |
|
EndsWith |
Determines the end character of a string, which can be intercepted |
|
Segmentation of Strings:
A.partition () |
Cut string A in a later character, return a tuple |
–a.partition (' love ') splits the string A with ' love ', contains the splitter before the splitter, the splitter, and the after part of the split character |
A.splitlines () |
Splits a string in a row, resulting in a list |
|
A.split () |
Splits the string from the left, you can specify the number of shards and objects, and the default is to slice the space , returning the list |
–a.split (') press ' ' to split a into a list? Escape character: tab \ t line break \ n |
A.rsplit () |
Splits the string from the right, you can specify the number of slices and objects, and the default is to slice by space |
|
Concatenation of strings:
'-'. Join (a) |
Inserts the specified character into each element of the subsequent sequence, stitching it together to form a new string |
b = '-'. Join (a) joins the string in the list with '-' |
+ |
Stitch Two strings together |
|
* |
Duplicates the specified string |
|
list built-in functions
list operation functions :
CMP (A, b) |
Compare two elements of a list, return 0, return 1 or 1 |
  |
Len (a) |
Get the number of elements in the list |
  |
Max (a) |
Returns the maximum value in the element |
  |
min (a) |
Returns the minimum value in the element |
  |
List (seq) |
Convert tuples to lists |
  |
List method:
a=[1,2,3]
A.append () |
Append a new element to the end of the list |
–a.append (4) Adding an object to the list 4 |
A.count () |
Count the number of occurrences of an element in a list |
–a.count (2) returns the number of occurrences of 2 in the list |
A.extend () |
Append a value from a sequence at the end of the list (extend the original list with a new list) |
–a.extend ([6,7,8]) adds the contents of the sequence to the list |
A.index () |
Find the index position of the first occurrence of a value in the list |
|
A.insert () |
Inserting an object into a list |
–a.insert (1, 100) inserting an object at a position with an index amount of 1 100 |
A.pop () |
Removes the last element in the list (and returns the value of the element) |
–a.pop (0) deletes and returns the object at the specified position 0, which is the last object by default |
A.remove () |
To remove the first occurrence of a value in a list |
–a.remove (100) Remove an object from the list 100 |
A.reverse () |
Elements in the reverse list |
–a.reverse () flip list in place |
A.sort () |
Sort the original list |
–a.sort () list element ordering |
Tuple Type Method
DictionaryType method
Dict = {' A ': 1, ' B ': 2}
–dict.has_key (' B ') if the key (key) exists in the dictionary, returns True, otherwise False
–dict.keys () Returns a list containing the keys in the dictionary
–dict.values () Returns a list that contains all the values in the dictionary
–dict.items () Returns a list containing the tuple (key, value) in the dictionary
dict2={' C ': 3}
–dict.update (DICT2) adds A dictionary dict2 key-value pair to the dictionary Dict
–dict.clear () Delete all the elements in the dictionary
Collection,
There can be only one string or list in the collection, which is used to repeat
A=set (' Novogene ')
A=set ([1,2,3,4,5,1,1])
? How to update a collection
A=set ([1,2,3,4,5])
–a.add (6) Adding an object in collection a 6
–t=[6,7,8]
–a.update (t) adds an iterator to an element in the T to a
–a.remove (1) Removes object 1 from collection A, and if 1 is not an element in collection a Keyerror error is thrown
–a.pop () deletes any object in collection A and returns it
application : Go heavy,
a=[1,1,2,3,4,2]
A=list (Set (a))
Unordered equality
A=[' A ', ' B ', ' C ']
b=[' B ', ' C ', ' a ']
A = = B
Set (a) = = set (b)
Python: String, List, collection, dictionary