Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Indexing and Slicing
What will be the output of this code?
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr[3])
A1
B2
C3
D4
Step-by-Step Solution
Solution:
  1. Step 1: Understand indexing in 1D array

    Index 3 means the fourth element because indexing starts at 0.
  2. Step 2: Identify element at index 3

    The array is [1, 2, 3, 4], so element at index 3 is 4.
  3. Final Answer:

    4 -> Option D
  4. Quick Check:

    arr[3] = 4 [OK]
Quick Trick: Index 3 accesses the fourth element in zero-based arrays [OK]
Common Mistakes:
  • Using 1-based indexing
  • Indexing out of range
  • Confusing element values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes