TypeError: a bytes-like object is required, not ‘str’
encode()方法语法:
str.encode(encoding='UTF-8',errors='strict')
print("gbk编码:",str.encode(encoding="gbk",errors="strict"))
‘tuple’ object has no attribute ‘encode’
Python有两个非常相似的集合式的数据类型,分别是list列表和tuple元组,定义形式常见的说法是数组。
tuple通过小括号( )定义,定义后无法编辑元素内容(即不可变),而list通过中括号[ ]定义,其元素内容可以编辑(即可变),编辑动作包含删除pop( )、末尾追加append( )、插入insert( ).
>>> name=['cong','rick','long']
>>> name[-2] #等同于name[1]
'rick'
>>> name.pop() #删除最后的元素
'long'
>>> name
['cong', 'rick']
>>> month=('Jan','Feb','Mar')
>>> len(month)
3
>>> month
('Jan', 'Feb', 'Mar')
>>> month[0]
'Jan'
>>> month[-1]
'Mar'
>>> month.appnd('Apr') #编辑元素内容会报错
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'appnd'
这是参另一个博客改的: