conversions between Python data types
function |
Description |
int (x [, Base]) |
Convert x to an integer |
Long (x [, Base]) |
Convert x to a long integer |
Float (x) |
Convert x to a floating-point number |
Complex (real [, Imag]) |
Create a complex number |
STR (x) |
Convert an object x to a string |
REPR (x) |
Convert an object x to an expression string |
eval (str) |
Used to evaluate a valid Python expression in a string and return an object |
Tuple (s) |
Converting a sequence s to a tuple |
List (s) |
Convert the sequence s to a list |
Set (s) |
Convert to mutable Collection |
Dict (d) |
Create a dictionary. D must be a sequence (key,value) tuple. |
Frozenset (s) |
Convert to immutable Collection |
Chr (x) |
Converts an integer to one character |
UNICHR (x) |
Converts an integer to a Unicode character |
Ord (x) |
Converts a character to its integer value |
Hex (x) |
Converts an integer to a hexadecimal string |
Oct (x) |
Converts an integer to an octal string |
To view variable data types:
A=3
Import types
Type (a)
Int (a) #转换为整型
STR (a) #转换为字符串
Python math functions
function |
return value (description) |
ABS (x) |
Returns the absolute value of a number, such as ABS (-10) returns 10 |
Ceil (x) |
Returns the top integer of a number, such as Math.ceil (4.1) returns 5 |
CMP (x, y) |
If x < y returns 1, if x = = y returns 0, if x > y returns 1 |
EXP (x) |
Returns the x power of E (ex), such as MATH.EXP (1) returns 2.718281828459045 |
Fabs (x) |
Returns the absolute value of a number, such as Math.fabs (-10) returns 10.0 |
Floor (x) |
Returns the lower integer of a number, such as Math.floor (4.9) returns 4 |
Log (x) |
If Math.log (MATH.E) returns 1.0,math.log (100,10) returns 2.0 |
LOG10 (x) |
Returns the logarithm of x with a base of 10, such as MATH.LOG10 (100) returns 2.0 |
Max (x1, x2,...) |
Returns the maximum value of a given parameter, which can be a sequence. |
Min (x1, x2,...) |
Returns the minimum value for a given parameter, which can be a sequence. |
MODF (x) |
Returns the integer portion of x and the fractional part, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type. |
Pow (x, y) |
The value after the x**y operation. |
Round (x [, N]) |
Returns the rounded value of the floating-point number x, if given an n value, that represents the digits rounded to the decimal point. |
sqrt (x) |
Returns the square root of the number x, the number can be negative, and the return type is real, such as MATH.SQRT (4) returns 2+0J |
Python random number function
function |
Description |
Choice (seq) |
Pick an element randomly from the elements of the sequence, such as Random.choice (range (10)), and randomly pick an integer from 0 to 9. |
Randrange ([Start,] stop [, step]) |
Gets a random number in the collection that increments by the specified cardinality from the specified range, and the base default value is 1 |
Random () |
Randomly generates the next real number, which is within the [0,1] range. |
Seed ([x]) |
Changes the seeding seed of the random number generator. If you don't know how it works, you don't have to specifically set Seed,python to help you choose Seed. |
Shuffle (LST) |
Randomly sort all elements of a sequence |
Uniform (x, Y) |
Randomly generates the next real number, which is within the [x, Y] range. |
The above discussion of the Python data type between the conversion is the small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we support foot topic.alibabacloud.com.