Post

@PythonPr Output A [2, 3]
-3 starts at value 2, and -1 is the stop index (exclusive), so it stops before the last element (4)
English

The "Only 1% Get This Right" claim is finally debunked. 🐍
The answer is A [2, 3].
Here’s why most people fail:
1️⃣ Negative indices count from the right (-3 is the value 2).
2️⃣ Python slices are exclusive of the stop index. It stops before -1.
Master your fundamentals and you're already in the top 1%. 🚀 #Python #Coding #ProgrammingTips

English

Ans---- (a)
The code uses list slicing with negative indices in Python.
In Python, negative indices count from the end of the list.
nums[-3] refers to the third element from the end, which is 2.
nums[-1] refers to the last element, which is 4.
The slice nums[-3:-1] includes elements starting from the index of nums[-3] up to, but not including, the index of nums[-1].
Therefore, the slice includes nums[-3] and nums[-2] (which is 3), resulting in the list [2, 3].
English

Answer: A) [2, 3]
Negative indices count from the end:
1 2 3 4
-4 -3 -2 -1
nums[-3:-1]:
› Start: -3 = 2
› Stop: -1 = 4 (exclusive!)
› Takes: -3(2), -2(3)
› Result: [2, 3]
For beginners: Stop index is always exclusive. -1 is the last item but not included! To include the last element omit the index entirely nums[-3:]
English

@PythonPr A) [2,3] is the right answer
Here we use concept of list slicing and negative indexing concept [start: end: stepsize].
English

@PythonPr [2, 3] Negative slicing: start = -3 →mean it need to count from backwards [4,3,2,1] when to count 3,it ends at [2], same with -1, count backwards, [3]
=[2,3]
English

@PythonPr A: [2, 3]
explaination:
nums=[1,2,3,4]
negativeIndex=[-4,-3,-2,-1]
nums[-3:-1]
logically becomes: nums[-3:-2]
hence the answer!
English


























