Python Forum
insert() but with negative index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
insert() but with negative index
#1
Inserting items with non-negative index gives expected results:
num = [1, 2, 3]
num.insert(0, "min")
print(num)
Output:
['min', 1, 2, 3]
but with negative index, as in this case shouldn't "max" be inserted at last index
num.insert(-1, "max")
print(num)
Output:
['min', 1, 2, 'max', 3]
I mean its not wrong its how they made python to work but why would they do so or am being stupid here?
Reply


Messages In This Thread
insert() but with negative index - by naughtysensei - Oct-01-2020, 02:06 AM
RE: insert() but with negative index - by micseydel - Oct-01-2020, 03:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Positive and negative numbers in a row peterp 1 1,798 Oct-29-2020, 02:42 AM
Last Post: deanhystad
  negative indices in lists Ironword 6 3,621 Jan-08-2020, 01:00 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020