What will be the output of the following Python code? [code]l=list('HELLO') p=l[0], l[-1], l[1:3] 'a={0}, b={1}, c={2}'.format(*p)[/code]

What will be the output of the following Python code?
Code:
l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)
A. Error
B. “a=’H’, b=’O’, c=(E, L)”
C. “a=H, b=O, c=[‘E’, ‘L’]”
D. Junk value
 
Answer: c
Explanation: In the code shown above, the value for a is substituted by l[0], that is ‘H’, the value of b is substituted by l[-1], that is ‘O’ and the value for c is substituted by l[1:3]. Here the use of *p is to unpack a tuple items into individual function arguments.
 

Tìm kiếm

Back
Top