Home > Backend Development > Python Tutorial > python data type conversion

python data type conversion

高洛峰
Release: 2016-10-19 16:12:11
Original
1369 people have browsed it

python type conversion

function                                                                                                                                                                                 Type conversion Convert x to a floating point number

complex(real [,imag ]) Create a complex number

str(x ) Convert object x to string

repr(x ) Convert object x to expression string

eval(str ) Converts the sequence s to a tuple

list(s ) Converts the sequence s to a list

chr(x ) Convert an integer to a character

unichr(x ) Convert an integer to a Unicode character

ord(x ) Convert a character to its integer value

hex(x ) Convert an integer to a hexadecimal Base string

oct(x) Convert an integer to an octal string

The sequence supports the following operations:

Operations Sequence connection

s * n , n * s n copies of , n is an integer


s % d                     String formatting (only strings)

s[i]                                  --                                                                

x in s , x not in s Subordination relationship

for x in s : Iteration

len(s) Length

min(s) Minimum element

max(s) Maximum element

s[i ] = x           Reassign s[i]

s[ i:j ] = r

x

x ^ y                                            . +y

x// y mod y )

-x                                                                                                                                                                                                                                                                 ​

abs(x) Absolute value

divmod(x,y) Return (int(x / y ), x % y )

pow(x ,y [,modulo ]) Return (x ** y ) x % modulo

round(x ,[n]) Rounding, n is the decimal point Digits

Yx >x> y is greater than

x == y equal to

x! = Y is not equal to (the same as

)

x> = y greater than equal to

x


🎜
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template