【英文】Python3的Zip学习笔记

Preface

Python3 Zip Learning Notes

Compose Tuples

  • Compose multiple tuples from multiple iterable objects based on the same index

  • If the lengths of multiple iterable objects are different, the number of tuples generated is based on the length of the shortest iterable object

  • Create multiple iterable objects

1
2
3
names = ["张三", "李四", "王五"]
ages = [18, 19, 20]
sexs = ['男', '女', '男']
  • Use Zip to generate tuples
1
arr = zip(names, ages, sexs)
  • Output the obtained return value
1
2
for i in arr:
print(i)
  • The result returned is
1
2
3
('张三', 18, '男')
('李四', 19, '女')
('王五', 20, '男')

Completion