enumerate(). Этот метод возвращает пару: индекс и элемент, упрощая работу с циклами.Пример:
fruits = ['apple', 'banana', 'cherry']
for index, fruit in enumerate(fruits):
print(f"{index}: {fruit}")
Вывод:
0: apple
1: banana
2: cherry
#PyTips
Please open Telegram to view this post
VIEW IN TELEGRAM
👨💻3
Пример:
names = ['Alice', 'Bob', 'Charlie']
scores = [85, 92, 78]
for name, score in zip(names, scores):
print(f"{name}: {score}")
Вывод:
Alice: 85
Bob: 92
Charlie: 78
#PyTips
Please open Telegram to view this post
VIEW IN TELEGRAM
👨💻4