Python Enumerate()

Write a program in Python to keep count of this given list starting from 100.

The list of items is -

["Suger", "Tea", "Rice", "Wheat", "Salt", "Pulse"]

Solution

The enumerate() is a predefined function in Python and used to add counter to an iteration and returns it in a form of enumerate object.


Syntax of Python enumerate()
enumerate(iterable, start=0)

Here, the iterable is a sequence, an iterator and start parameter is the number from where the counting starts. This is an optional parameter, by default 0 is taken as starting number.

This is the following solution to keep count of this given list starting from 100.

items = ["Suger", "Tea", "Rice", "Wheat", "Salt", "Pulse"]

# set the start index to 100
for count,ele in enumerate(items,100):
	print count,ele

Output of the above code
Python Enumerate


Related Articles

Python program for Prime Number
Odd Even Program in Python
Python program to convert Celsius to Fahrenheit
Python Convert XML to CSV
Python Text to Speech
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml




Read more articles


General Knowledge



Learn Popular Language