Python · Question 2 · Easy

What will be the output of the following Python code?

s = "placement"
print(s[2:5], s[-1])
  1. acem t
  2. ace t
  3. lac t
  4. ace p
Answer and explanation

Answer: B. ace t

Explanation: Slicing s[2:5] takes indices 2, 3 and 4 (the end is excluded): 'a', 'c', 'e'. s[-1] is the last character, 't'.

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