In the above example zip takes 3 strings as an argument.
1st iteration : when the first time "for" works, zip takes all first
elements from each three strings and return it as a tuple => ('1',
'4', '7')
2nd iteration zip returns = > ('2', '5', '8')
3rd iteration zip returns => ('3', '6', '9')
for t in zip('123','456','789'):
print(t)
('1', '4', '7')
('2', '5', '8')
('3', '6', '9')
转到你的问题
s=['你好','你好','零']
*s => will unpack the list into 3 items.
zip(*s) => zip('hello','hullo','zeros')
for t in zip(*s):
('h', 'h', 'z')
('e', 'u', 'e')
('l', 'l', 'r')
('l', 'l', 'o')
('o', 'o', 's')
工作zip函数:
转到你的问题
s=['你好','你好','零']
你可以试试这个:
输出:
编辑:函数方法:
相关问题 更多 >
编程相关推荐