Python的列表如果对字符串用expend, 会按每个字符添加,append方法把字符串看成一个整体添加到一个列表。expend添加的对象默认是迭代器。
f = []
g = []
b = 'hello'
f.extend(b)
g.append(b)
print(f)
print(g)
输出:
['h', 'e', 'l', 'l', 'o']
['hello']
Python的列表如果对字符串用expend, 会按每个字符添加,append方法把字符串看成一个整体添加到一个列表。expend添加的对象默认是迭代器。
f = []
g = []
b = 'hello'
f.extend(b)
g.append(b)
print(f)
print(g)
输出:
['h', 'e', 'l', 'l', 'o']
['hello']