Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
NumPy - Fundamentals
What will be the output of this code?
import numpy as np
arr = np.array([10, 20, 30])
print(arr[1])
A20
B10
C30
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing

    NumPy arrays use zero-based indexing, so index 1 refers to the second element.
  2. Step 2: Identify the element at index 1

    The array is [10, 20, 30], so element at index 1 is 20.
  3. Final Answer:

    20 -> Option A
  4. Quick Check:

    Index 1 element = 20 [OK]
Quick Trick: NumPy arrays start at index 0 [OK]
Common Mistakes:
  • Confusing index 1 with first element
  • Expecting error due to indexing
  • Mixing up array elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes