Python · Question 25 · Medium

What will be the output of the following Python code?

print([i for i, c in enumerate("kerala") if c == "a"])
  1. [3]
  2. ['a', 'a']
  3. [4, 6]
  4. [3, 5]
Answer and explanation

Answer: D. [3, 5]

Explanation: enumerate pairs each character with its 0-based index: k0 e1 r2 a3 l4 a5. The letter a is at indices 3 and 5.

Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?

Practise python

Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.

More python questions

More technical & programming practice

Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge