Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Python code snippet?
print(‘abcd’.translate({‘a’: ‘1’, ‘b’: ‘2’, ‘c’: ‘3’, ‘d’: ‘4’}))

What will be the output of the following Python code snippet?
print(‘abcd’.translate({‘a’: ‘1’, ‘b’: ‘2’, ‘c’: ‘3’, ‘d’: ‘4’}))
a) abcd
b) 1234
c) error
d) none of the mentioned

Answer: a
Explanation: The function translate expects a dictionary of integers. Use maketrans() instead of doing the above.

Join The Discussion