Home > Blockchain >  Printing Out Python Middle Values
Printing Out Python Middle Values

Time:04-29

How would you print out the middle values in a list, for example if a list is given [1, 2, 3, 4, 5], the values 2,3,4 would be printed out.

CodePudding user response:

You can do this:

lst = [1, 2, 3, 4, 5]
print(lst[1:-1])

CodePudding user response:

lst = list(range(1,6))

lst
Out[2]: [1, 2, 3, 4, 5]

lst[1:-1]
Out[3]: [2, 3, 4]
  • Related