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?
‘%(qty)d more %(food)s’ %{‘qty’:1, ‘food’: ‘spam’}

What will be the output of the following Python code snippet?
‘%(qty)d more %(food)s’ %{‘qty’:1, ‘food’: ‘spam’}
a) Error
b) No output
c) ‘1 more foods’
d) ‘1 more spam’

Answer: d
Explanation: String formatting also allows conversion targets on the left to refer to the keys in a dictionary coded on the right and fetch the corresponding values. In the code shown above, (qty) and (food) in the format string on the left refers to keys in the dictionary literal on the right and fetch their assorted values. Hence the output of the code shown above is: 1 more spam.

Join The Discussion