Python built-in data structures First, the numerical type 1. Data type classification: int: integer
Python3 int is a long integer with no size limit and is limited by the size of the memory area
int (x) returns an integer
float: floating point
There are integers and fractional parts. Supports decimal and scientific notation notation. Only double-precision.
Float (x) returns a floating-point number
Complex: plural
There are real and imaginary parts, the real and imaginary part are floating-point numbers, 3+4.2j
Complex (x), complex (Y) returns a complex number
BOOL: Boolean
Subclass of int, only 2 instances True, false corresponds to 1 and 0, can be directly calculated with integers
BOOL (x) returns a Boolean value, and the bool value judgment logic is as described earlier, such as:
BOOL (")---False
BOOL (0)---False
2. Numeric processing functions: (1) int (), floor (), ceil (), round (),///difference: Int ():
Builtin built-in functions
Official Document Description:
class int (x=0)
class int (x, base=10)
Return an integer object constructed from a number or string x, or return 0 if no arguments is given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must are a string, bytes, or ByteArray instance representing an integer li Teral in Radix base. Optionally, the literal can be preceded by + or – (with no space in between) and surrounded by whitespace. A base-n literal consists of the digits 0 to n-1 and with A to Z (or A to Z) has the values of 35. The default base is 10. The allowed values are 0 and 2–36. Base-2,-8, and-16 literals can be optionally prefixed with 0b/0b, 0o/0o, or 0x/0x, as with the integer literals in code. Base 0 means to interpret exactly as a code literal, so then the actual base is 2, 8, ten, or, and so that int (' 010 ', 0) Is isn't legal, while INT (' 010 ') are, as well as int (' 010 ', 8).
For floating-point numbers, truncate decimals to 0
That is, take the whole number of parts
Floor ():
Math Template
Rounding down
Ceil ():
Math Template
Rounding up
Round ():
Four homes six into five to take even
//:
Divide and Floor ()
Floored quotient of X and Y
(2) Digital processing function _2min ()
Min (iterable, [, Key, default])
Min (arg1, arg2, args[, key])
Max ()
Max (iterable, [, Key, default])
Max (Arg1, arg2, args[, key])
Pow (x, y)
Same function as X**y
MATH.SQRT ()
Prescribing
Bin ()
The return value is a string
Oct ()
The return value is a string
Hex ()
The return value is a string
MATH.PIMATH.E (3) Type-judging types (obj)
return type rather than string
Isinstance (obj, class_or_tuple)
Returns a Boolean value
Second, Sequence object Data type classification: 1.STR: string 2.list: List
The elements in the list are in order and can use the index
A linear data structure
The list is mutable
Initialization
Cases:
lst=list()lst=[]lst=[1,2,‘a‘,[‘i‘,‘j‘]]lst=[range(5)]
Size can not be defined at the beginning, compared to Java
List, linked lists, queue, stack differences
List linear storage, high query efficiency O (n), insert, delete inefficient O (n)
Linked list scattered in memory, query efficiency low O (n), insert, delete high efficiency O (1)
Queue FIFO First
Stack LIFO LIFO
List Index Access
Positive index: From left to right, starting with 0, numbering each element in a list
Negative index: From right to left, starting from-1
List Query
Index (Value,[start,[stop]])
Returns the index of the first occurrence
Can only traverse from left to right
No match to return ValueError exception
Time complexity O (n), because of the need to traverse the list
Count (value)
Returns the number of occurrences of the value in the list
Time complexity O (n), because of the need to traverse the list
Len ()
Time complexity O (1)
Counter performs a count on each insertion and deletion to the list
Therefore, when you call Len (), only the counter value is typed and no traversal is performed
List increment, insert element append (object), None
Append at tail, return none
Modify an existing object without generating a new object
Time complexity O (1)
Insert (Index, object), None
Inserts an element at the specified index, returning none
Modify an existing object without generating a new object
Time complexity O (n), because subsequent elements may occur after insertion in memory to move back in and out of action
If the index is not error-bound:
Beyond the upper bound, trailing append
Beyond the Nether, head append
Extend (iteratable), None
Appends elements of an object that can be iterated back, returning none
Modify an existing object without generating a new object
+ List
Connection operation, connecting two lists
Create a new object, the original list does not change
The add() method is essentially called
* List
Repeat, repeat the list element n times to return the new list
Attention:
x=[[1,2,3]]y=x*3y[0][1]=200y
The result is:
[[1, 200, 3], [1, 200, 3], [1, 200, 3]]
y = [1]*5y[0] = 6y[1] = 7print(y)
The result is:
[6, 7, 1, 1, 1]
Can be temporarily understood as:
* Copy, for complex objects, copy the reference, not the data, the copied three elements actually point to the same memory address
Simple objects do not affect
List Delete element Remove (value), None
Finds the first value that matches value from left to right, removes the element, and returns none
Modify an existing object without generating a new object
Time complexity O (n), because subsequent elements may occur in memory after insertion (the list is stored sequentially in memory)
Pop ([index]), item
An element is popped from the tail of the list without specifying index
Specifies index, which pops an element from the index, and the index bounds throws a indexerror error
Complexity of Time:
Do not specify an index of O (1)
Specifies that the index is O (n) because subsequent elements may occur in memory after the insertion (the list is stored sequentially in memory)
Clear (), None
Clears all elements of the list, leaving an empty list
List other operations reverse ()-None
Reverses the list element, returning none
Modify an existing object without generating a new object
Sort (Key=none, reverse=false), None
Sort list elements by default ascending
Modify an existing object without generating a new object
Reverse is true, reversed, descending
Key A function that specifies how key is sorted
In3.tuple: meta-Group Three, key-value pairs Data type classification: set: Set Dict: Dictionary
Python's first week of study notes _ to be added (3)