python错误提示:TypeError: expected string or bytes-like object(预定的数据类型或者字节对象相关)
一般为数据类型不匹配造成的。
Python3中有六个标准的数据类型:
- Number(数字)
- string(字符串)
- List(列表)
- Tuple(元组)
- Sets(集合)
- Dictionary(字典)
可以通过print(type(object))来查当前的数据类型,式中object为要查询的对象。
python中数据类型转换
因为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
注意括号的位置!
类型转换:https://blog.csdn.net/shanliangliuxing/article/details/7920400