PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 63


What is the expected output of the following code?

mytu = ('a', 'b', 'c')

m = tuple(map(lambda x: chr(ord(x) + 1), mytu))

print(m[-2])

Show Answer
Correct Answer: D

The code snippet converts each character in the tuple 'mytu' ('a', 'b', 'c') to the next character in the ASCII sequence using a lambda function inside the map function. The characters 'a', 'b', and 'c' will be converted to 'b', 'c', and 'd' respectively. When the result is converted back to a tuple and stored in 'm', it becomes ('b', 'c', 'd'). Accessing the second last element, m[-2], will give 'c'.

Discussion

2 comments
Sign in to comment
DKAT2023Option: D
Jul 12, 2024

D is the correct

kstrOption: D
Jul 12, 2024

D right answer