Python implements data type conversions with built-in functions
| Grammar |
Example |
Describe |
| Int () |
Int (1.0), int (' 1 ') |
Can be converted to include string types and other numeric types, but will lose precision |
| Float () |
Float (1), float (' 1 ') |
You can convert string and other numeric types, and the insufficient number of digits is 0, for example 1 becomes 1.0 |
| STR () |
STR (1) |
Convert to String |
| Complex (real, imag) |
|
Plural |
| Repr |
Repr (Object) |
Returns the string format of an object |
Eval () |
Eval ("12+23") |
Executes a string expression that returns the result of the calculation, as shown in the example 35 |
Tuple () |
|
Convert to tuple |
List () |
|
Convert to List |
Set () |
|
Convert to a collection, while going back to the |
Frozenset () |
Frozenset ([0, 1, 2, 3]) |
Transforms an iterative object into an immutable collection |
Chr () |
|
|
Ord () |
Ord (' a ') |
Returns the corresponding ASCII value |
Hex () |
Hex (12) |
Convert an integer to a hexadecimal string |
Oct () |
Oct (12) |
Convert an integer to an octal string |
python--Data type Conversions