Contents

What will be the output of the following Python code?
a) [‘ab’, ‘cd’]                       
b) [‘AB’, ‘CD’]
c) [None, None]   
d) none of these

a

Explanation: The function upper() does not modify a string in place, it returns a new string which isn’t being stored anywhere.


What will be the output of the following Python code?
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
c) [‘ab’, ‘cd’]                        
d) none of these

d

Explanation: The loop does not terminate as new elements are being added to the list in each iteration.


What will be the output of the following Python code?
a) 1 2                                     
b) 1 2 3
c) error                                  
d) none of these

b

Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.


What will be the output of the following Python code?
a) 1 2 3 4 5 6                       
b) 1 2 3 4 5 6 7
c) error                                  
d) none of these

a

Explanation: Control exits the loop when i becomes 7.


What will be the output of the following Python code?
a) 5 6 7 8 9 10                     
b) 5 6 7 8
c) 5 6                                     
d) error

b

Explanation: 0O11 is an octal number.


What will be the output of the following Python code?
a) 5 6 7 8                                              
b) 5 6 7 8 9
c) 5 6 7 8 9 10 11 12 13 14 15 ….
d) error

d

Explanation: 9 isn’t allowed in an octal number.