Cloud Services
AWS
Azure
Google Cloud
Salesforce
Microsoft
SAP
Work with our skilled Python developers to accelerate your project and boost its performance.
Hire Python DevelopersJanuary 10, 2024
You can use the enumerate function in Python to iterate over a sequence and simultaneously get the index and the value. Here’s how you can modify your code to achieve the desired output:
xs = [8, 23, 45] for index, x in enumerate(xs, start=1): print("item #{} = {}".format(index, x))