Bird
0
0

In Ruby, what does str[0] return when str = "hello"?

easy📝 Conceptual Q11 of 15
Ruby - String Operations
In Ruby, what does str[0] return when str = "hello"?
AThe first character of the string, 'h'
BThe entire string 'hello'
CThe last character of the string, 'o'
DAn error because indexing starts at 1
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby string indexing

    Ruby strings are indexed starting at 0, so the first character is at index 0.
  2. Step 2: Apply indexing to the string 'hello'

    Accessing str[0] returns the first character 'h'.
  3. Final Answer:

    The first character of the string, 'h' -> Option A
  4. Quick Check:

    Index 0 = 'h' [OK]
Quick Trick: Remember Ruby indexes start at zero for strings [OK]
Common Mistakes:
MISTAKES
  • Thinking indexing starts at 1
  • Expecting the whole string instead of one character
  • Confusing last character with first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes