What will be the output of the following Python code? [code]l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)[/code]

What will be the output of the following Python code?
Code:
l=list('HELLO')
'first={0[0]}, third={0[2]}'.format(l)
A. ‘first=H, third=L’
B. ‘first=0, third=2’
C. Error
D. ‘first=0, third=L’
 
Answer: a
Explanation: In the code shown above, the value for first is substituted by l[0], that is H and the value for third is substituted by l[2], that is L. Hence the output of the code shown above is: ‘first=H, third=L’. The list l= [‘H’, ‘E’, ‘L’, ‘L’, ‘O’].
 

Tìm kiếm

Back
Top