A numerical string
int, float type
Python's in, float type with respect to any other language explicitly limit the scope, Python's int, float type can store much value is determined by the hardware.
Decimal can write directly
Octal is beginning 0o
Beginning hexadecimal 0x
Binary beginning 0b
Mathematical Operators
+ Plus
- Less
* Multiplication If a string is multiplied by a digital representation of the string is repeated several times
** computing power
/ Division
// divisible
% Remainder
Value of built-in functions and the tool module
Built-in functions
int () is converted into numeric type int int (value, hexadecimal) example: int ( "1101", 2) int ( "177", 8) int ( "9ff", 16)
float () into a float value
round () rounding
bin (Number) converted to a binary
oct (Number) into octal
hex (Number) into hexadecimal
Tool module math, import module
Function in the math module
floor () to go the whole, to take the direction of a smaller [3..14 3 is obtained, the obtained -3..14] -4
the trunc () toward the value 0 is obtained 3.14 [3, -3] was obtained -3.14
ceil () rounded up to the big direction is taken to obtain 3.14 [4, -3] was obtained -3.14
math.pi can obtain the value of π
pow fourth power (2,4) 2
sqrt (81) square root
Precision floating-point processing
Under normal circumstances, the figure should be 0, but other values obtained. This is the accuracy issue.
When decimal accuracy modules able to solve this problem, the module provides a class Decimal, attention needs to pass a string value of
Another way of introducing
The nature of Bool
Only true and false bool corresponding to 0 and 1
BOOL built-in function () value is converted into a value Bool
0, 0.0, [], {}, '', None will be converted to false
Second, the list (list)
(1) an ordered set of arbitrary objects
(2) access through the index table elements, as shown below can be used even negative accessed, -1 is the last element
Index range [0: 2] left and right open and closed (does not include the right)
(3) a variable length. append additional methods
(4) any nested
(5) support for in-situ change can be seen from the 25 became 26
Spoken operation:
(. 1) the function list, the list is converted to a value
If (2) is determined which elements in the set {(in), (not in)]
(3) coupled to a sequence list1 + list2 [list1, list2 itself no change]
(4) repeat sequence content list1 * n (n represents a repeating several times), itself has not changed [list1]
(5) Get subscript index to access the specified range of elements
Range visit cities [: 2] do not write earlier, the default starting from 0.
cities [1:] do not write back, access to the last
cities [:] does not write access to all
(6) access syntax specified index value in steps of access: list1 [i: j: k]
k is the step value. k = 2. That is, every 2 to take a. (Taken every k 1, k less than the last one, when a fetch k)
(7) the length of the acquisition sequence. len function
General function part (8) of the list
The maximum value (max)
The minimum value (min)
The sum (sum)
Acquisition of an element in the following table list.index (x)
Get Occurrence list.count certain elements appear in the list (x)
Variable sequence list and general procedure
(1) changing the value of an element of the list [0] = x
(2) the changing value list [n: m] within a certain range = t. t represents a value of the iteration may be, must be consistent with the number of the replacement range
(3) remove elements del. Another written deletion range x [0: 2] = [] is equal to an empty sequence is also a deleted
(4) list.remove (x) to delete a value. And if the same value, then remove the first matching value
(5) list.clear () Clear List
(6) Additional elements list.append (x) and extension elements s.extend (list) [the difference between]
(7) list.insert (index, value) index position index, value specific value. Inserting a value in a specified position
list.insert (0, 3.14) is equal to list [0: 0] = [3.14]
(8) list.pop (index) to remove elements specified index, and delete the value returned.
(9) list.reverse () reversed. It does not return a value. But change their position elements
(10) replicating sequence
list.copy()
y = list.copy () is equivalent to y = list [:]
(11) Sort list.sort () does not return a value, but also affect the itself
Reverse list.sort (key = None, reverse = True) parameters are reversed and sorted (list) returns a new result. It does not affect the itself