python数据类型转换(str跟int的转换)

原文地址为: python数据类型转换(str跟int的转换)

因为python跟java在数据类型转换方面语法不同,所以总是搞混,特此记录下来,方便查阅:

在python中:

字符串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)

在java中:

字符串String转换成int: int_value = String.parseInt(string_value)或(int)string_value

int转换成字符串String: string_value = (String)int_value

注意括号的位置!


转载请注明本文地址: python数据类型转换(str跟int的转换)

猜你喜欢

转载自blog.csdn.net/xfxf996/article/details/80930414
今日推荐