I have a question about python.
I need to print two variables stored in a list. example list1 = ["1", "2", "3"] list2 = ["a", "b", "c"]
output print: 1a, 2b, 3c
You want zip
.
for i1, i2 in zip(list1, list2):
print(i1 + i2)
You can use zip()
and .join()
to produce the desired output:
list1 = ["1", "2", "3"]
list2 = ["a", "b", "c"]
# Prints 1a, 2b, 3c
print(', '.join(''.join(item) for item in zip(list1, list2)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.