Python Strings · Question 20 · Hard
Two step slices of a word are joined, the second one reversed. What does this print?
s = "Python"
print(s[::2] + s[1::2][::-1])
- Ptoyhn
- Ptonhy
- nhyPto
- Pythno
Answer and explanation
Answer: B. Ptonhy
Explanation: s[::2] takes indexes 0, 2, 4: "Pto". s[1::2] takes indexes 1, 3, 5: "yhn", and [::-1] reverses it to "nhy". Joined together they give Ptonhy.
Previous: Three pairs of strings are compared with the less-than operator. What is the…
Practise python strings
Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.
More python strings questions
- split() and rsplit() are each limited to one split. What does this print?
- strip() is given a string of characters as its argument. What does this print?
- Three pairs of strings are compared with the less-than operator. What is the…
More python practice
Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge