Kotak Perkakas Python
Hugo Bowne-Anderson
Data Scientist at DataCamp
avengers = ['hawkeye', 'iron man', 'thor', 'quicksilver'] names = ['barton', 'stark', 'odinson', 'maximoff']z = zip(avengers, names)print(type(z))
<class 'zip'>
print(list(z))
[('hawkeye', 'barton'), ('iron man', 'stark'),
('thor', 'odinson'), ('quicksilver', 'maximoff')]
def raise_both(value1, value2):
"""Raise value1 to the power of value2
and vice versa."""
new_value1 = value1 ** value2
new_value2 = value2 ** value1
new_tuple = (new_value1, new_value2)
return new_tuple
Dasar
[ekspresi keluaran untuk variabel iterator dalam iterable]
Lanjutan
[ekspresi keluaran +
kondisional pada keluaran untuk variabel iterator dalam iterable +
kondisional pada iterable]
Kotak Perkakas Python