Python · Question 18 · Easy

What will be the output of the following Python code?

s = "Bengaluru"
print(s.count("u"), s.find("g"))
  1. 1 3
  2. 2 3
  3. 3 3
  4. 2 4
Answer and explanation

Answer: B. 2 3

Explanation: "Bengaluru" contains u twice (positions 6 and 8). find returns the first index of "g", which is 3 (B=0, e=1, n=2, g=3).

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