-5

Example: My code:

lst=[15,18,20,1,19,65]
print(lst[2])

It prints 20, but I want my array to be 1-indexed and print 18 instead.

98,67,86,3,4,21

When I print the second number it should print 67 and not 86 based on indexing. First number is 98 Second number is 67 Third number is 86 and so on. How to make my program have index 0 become index 1 and so on?

ruohola
  • 21,987
  • 6
  • 62
  • 97

2 Answers2

7

This cannot be done, Python's list and every other sequence is inherently 0-indexed. The same is true for the vast majority of modern programming languages. I would suggest you to just learn to live with it, it will not be the hardest thing in your programming career.

ruohola
  • 21,987
  • 6
  • 62
  • 97
1

Subtract 1 from the index you are actually trying to look up.

print(lst[2-1])
NewPythonUser
  • 361
  • 1
  • 9