Explanation:
๐น Line 1: Create a List
x = [10, 20, 30]
Python creates a list containing three elements.
Current list:
x = [10, 20, 30]
Index positions:
Positive Index
0 1 2
│ │ │
10 20 30
Negative index positions:
Negative Index
-3 -2 -1
│ │ │
10 20 30
๐น Line 2: Call print()
print(x[-0])
Before printing, Python first evaluates:
x[-0]
๐น Step 1: Evaluate -0
Many people think:
-0
is a special negative index.
❌ That's incorrect.
Python first calculates:
-0
which is simply:
0
Because mathematically:
-0 = 0
There is no separate "negative zero" integer in Python.
Proof:
print(-0)
Output:
0
๐น Step 2: Access the List Element
Now Python replaces:
x[-0]
with:
x[0]
The element at index 0 is:
10
๐น Visual Representation
Original expression:
x[-0]
↓
Evaluate:
-0
↓
Becomes:
0
↓
Expression becomes:
x[0]
↓
Result:
10
๐น Step 3: Print the Result
Python now executes:
print(10)
Output:
10

0 Comments:
Post a Comment