Data
The data structure is simple to understand that it is a structure that can handle some data, or that it is used to store a set of related data.
There are three types of built-in data structures in Python: Lists, tuples, and dictionaries.
List: Items in the list should be included in square brackets; Once a list is created, we can add, delete, or search items in the list, which is a mutable data type, which can be changed.
Tuples: Tuples and lists are very similar, except that tuples and strings are immutable, that is, you cannot modify tuples. Tuples are defined by a comma-delimited list of items in parentheses.
The method and explanation of the string:
Capitalize () change the first letter of a string to uppercase #list. Capitalize ()
Casefold () changes the entire string's capital letter to lowercase #list. Casefold ()
Center (width, '-') centers the string and fills the new string with a custom symbol to the width of length #list. Center (30, ' # ')
COUNT (sub) Returns the number of occurrences of a sub in a string #list. Count (s)
EndsWith (sub) checks whether the string ends with a sub, and returns True if it is false
StartsWith (prefix) checks if the string starts with prefix, and if true, returns false
Expandtabs ([tabsize=8]) converts the tab (\ T) in a string to a space, and if you do not specify a parameter, the default number of spaces is 8
Find (sub) checks if the sub is contained in a string, if there is a return index value, if no return-1
Index (sub) is the same as find, but an exception occurs if the sub is not in a string
Isalnum () returns True if the string has at least one character and all characters are letters or numbers, otherwise false
Isalpha () returns True if the string has at least one character and all characters are letters, otherwise false
Isdecimal () returns True if the string contains only decimal digits, otherwise false
IsDigit () returns True if the string contains only numbers, otherwise false
Islower () returns True if the string includes at least one case-sensitive character, and the characters are lowercase
Isspace () returns True if the string contains only spaces
Title () returns the caption (the word starts with uppercase, the remaining letter is lowercase)
Istitle () returns True if the string is a caption (all words start with uppercase and the remaining letters are lowercase)
Isupper () returns true if at least one case-sensitive character is included in the string, and the characters are uppercase
Join (sub) inserts a string as a delimiter into all of the characters in the sub # '--'. Join (sub)
Ljust (width, '-') returns a left-aligned string and fills it with a space or custom character to a new string of length width
Rjust (width, '-') returns a right-aligned string and fills it with a space or custom character to a new string of length width
Lower () converts all uppercase characters in a string to lowercase
Upper () converts all lowercase letters in a string to uppercase
Strip ([chars]) removes all whitespace from the front and back of the string, chars parameter can be customized to delete the character, optional
Lstrip () cancels all whitespace in the left side of the string
Rstrip () Cancels all spaces at the end of the string
Partition (sub) finds a substring sub and divides the string into a 3-tuple (Pre_sub,sub,fo_sub) if the string does not contain a sub then Returns (' original string ', ' ', ‘‘)
Rpartition (sub) is similar to partition (), but starts from the right
Replace (Old,new[,count]) replaces the old substring in the string with the new substring, if count specifies no more than count times
RFind (sub) is similar to find (), except that it starts from the right
Rindex (sub) is similar to index (), except that it starts from the right
Split (sep=none,maxsplit=-1) without parameters is the default slice string with a space delimiter, and if the Maxspit parameter has a setting, only maxsplit substrings are delimited, returning the slice after the Sub-string concatenation list
Splitlines ([keepends]) is separated by ' \ n ', returns a list containing the rows as elements, and if Keepends is specified, returns the first Keepends row
Swapcase () Flips the case in a string
Zfill (width) returns a string of length width, the original string is right aligned, and the front is filled with 0
Python Learning-baseno.2