python各种类型转换

python各种类型转换

学习了:https://blog.csdn.net/shanliangliuxing/article/details/7920400

https://blog.csdn.net/sunlylorn/article/details/8547818

int(x [,base ])         将x转换为一个整数    
long(x [,base ])        将x转换为一个长整数    
float(x )               将x转换到一个浮点数    
complex(real [,imag ])  创建一个复数    
str(x )                 将对象 x 转换为字符串    
repr(x )                将对象 x 转换为表达式字符串    
eval(str )              用来计算在字符串中的有效Python表达式,并返回一个对象    
tuple(s )               将序列 s 转换为一个元组    
list(s )                将序列 s 转换为一个列表    
chr(x )                 将一个整数转换为一个字符    
unichr(x )              将一个整数转换为Unicode字符    
ord(x )                 将一个字符转换为它的整数值    
hex(x )                 将一个整数转换为一个十六进制字符串    
oct(x )                 将一个整数转换为一个八进制字符串  
字符串str转换成int: int_value = int(str_value)

int转换成字符串str: str_value = str(int_value)

int -> unicode: unicode(int_value)

unicode -> int: int(unicode_value)

str -> unicode: unicode(str_value)

unicode -> str: str(unicode_value)

int -> str: str(int_value)

str -> int: int(str_value)

猜你喜欢

转载自www.cnblogs.com/stono/p/8975746.html