第一题
list1 = [“name”,“author”,“introduce”]
list2 = [“NORWEGIAN WOOD”,“Haruki Murakami”,“balabalabala…”]
将list1与list2以键值对的形式呈现
list1 = ["name","author","introduce"]
list2 = ["NORWEGIAN WOOD","Haruki Murakami","balabalabala..."]
def temp(a,b):
return(a,b)
print(dict(map(temp,list1,list2)))
list1 = ["name","author","introduce"]
list2 = ["NORWEGIAN WOOD","Haruki Murakami","balabalabala..."]
print(dict(zip(list1,list2)))
第二题
Amy_info = {‘name’:‘Amy’,‘addr’:‘hunan’,‘weight’:90}
获取Amy_info的key value
Amy_info = {'name':'Amy','addr':'hunan','weight':90}
print(Amy_info.keys())
print(Amy_info.values())
第三题
字节转字符串
bytes转str
- bytes.encode() -->解码
In [3]: bt = bytes("hello",encoding = "utf8")
In [4]: bt.decode()
Out[4]: 'hello'
字符串转字节 - str转bytes S.decode() -->编码
In [5]: str = ("python")
In [6]: str.encode()
Out[6]: b'python'