Menu

Objective Type Questions & Answers


Python Programming -Unit-2 Objective Type Questions



1. Which of the following is invalid identifier declaration?

A . _a = 1

B . __a = 1

C . __str__ = 1

D . none of the mentioned

Answer


2. Which of the following is an invalid statement?

A . abc = 1,000,000

B . a b c = 1000 2000 3000

C . a,b,c = 1000, 2000, 3000

D . a_b_c = 1,000,000

Answer


3. What error occurs when you execute?  
>>>apple = mango

A . SyntaxError

B . NameError

C . ValueError

D . TypeError

Answer


4. What is the output of the following?

x = [`ab`, `cd`]
for i in x:
    x.append(i.upper())
print(x)

A . [‘AB’, ‘CD’].

B . [‘ab’, ‘cd’, ‘AB’, ‘CD’].

C .  [‘ab’, ‘cd’].

D . none of the mentioned

Answer


5. True = False
while True:
    print(True)
    break

A . 1

B .

C . Error

D . none of the mentioned

Answer


6. What is the output of the following?

for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

A . 0 1 2 3 4 Here

B .  0 1 2 3 4 5 Here

C . 0 1 2 3 4

D . 1 2 3 4 5

Answer


7. What is the output of the following?

print("xyyzxyzxzxyy".count(`xyy`, -10, -1))

A . 2

B . 0

C . 1

D . Error

Answer


8. What is the output of the following?

print("ab\tcd\tef".expandtabs(1))

A . ab cd ef

B . abcdef

C . ab cd ef

D . Error

Answer


9. What is the output of the following?

print(`ab,12`.isalnum())

A . 1

B .

C . Error

D . none of the mentioned

Answer


10. What is the output when following code is executed ?

myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
    myList[i - 1] = myList[i]
 
for i in range(0, 6): 
    print(myList[i], end = " ")

A . 2 3 4 5 6 1

B . 6 1 2 3 4 5

C . 2 3 4 5 6 6

D . 1 1 2 3 4 5

Answer


11. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
 
v = values[0][0]
for row in range(0, len(values)):
    for column in range(0, len(values[row])):
        if v < values[row][column]:
            v = values[row][column]
 
print(v)

A . 3

B . 5

C . 6

D . 33

Answer


12. What will be the output?

>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print(len(my_tuple))

A . 7

B . 4

C . 3

D . Error

Answer


13. Is the following piece of code valid?

>>> a=(1,2,3,4)
>>> del a

A . Yes, the entire tuple is deleted

B . Yes, first element in the tuple is deleted

C . No because tuple is immutable

D . No, invalid syntax for del method

Answer


14.  What is the output for the following piece of code?

>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> print(a)

A . {1,2,3}

B . {1,2}

C . Error, copying of sets isn’t allowed

D . Error, invalid syntax for remove

Answer


15. What is the output of the following code?

>>> a={1,2,3}
>>> b=a.add(4)
>>>print(b)

A . None

B . {1,2,3,4}

C . {1,2,3}

D . Error

Answer


16. The ____________ function removes the first element of a set and the last element of a list.

A . remove()

B . discard()

C . clear()

D . pop()

Answer


17. The difference between the functions discard and remove is that:

A . Discard removes the last element of the set whereas remove removes the first element of the set

B . Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element

C . Remove removes the last element of the set whereas discard removes the first element of the set

D .  Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element

Answer


18. What is the output of the following code?

a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])

A . [2,3,4]

B . 3

C . 2

D . 1

Answer


19. What is the output of the following piece of code?

>>> a={`B`:5,`A`:9,`C`:7}
>>> print(sorted(a))

A . [‘A’,’B’,’C’].

B . [‘B’,’C’,’A’].

C . [5,7,9].

D . [9,5,7].

Answer


20. What is the output when following code is executed ?

>>>names = [`Amir`, `Bear`, `Charlton`, `Daman`]
>>>print(names[-1][-1])

A . A

B . Daman

C . n

D . Charlton

Answer


21. What is the output of the following?

a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0],end=" ")

A . 0 0 0 0

B . 0 1 2 3

C . 0 1 2 2

D . 3 3 3 3

Answer


22. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?

A .  [2, 33, 222, 14].

B . Error

C . 25

D . [25, 14, 222, 33, 2].

Answer


23. What is the output when following code is executed ?

def f(values):
    values[0] = 44
 
v = [1, 2, 3]
f(v)
print(v)

A . [1, 44].

B . [1, 2, 3, 44].

C . [44, 2, 3].

D . [1, 2, 3].

Answer


24. What will be the output?

>>>t=(1,2,4,3)
>>>print(t[1:-1])

A . (1,2)

B . (2,3)

C . (1,3)

D . (2,4)

Answer


25. What is the output of the following piece of code?

a={1:"A",2:"B",3:"C"}
print(a.get(1,4))

A . 1

B . A

C . 4

D . Error

Answer




Relevant Materials :

Python Programming -Unit-1 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-2 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-3 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-4 Objective Type Questions - [ Python Programming ]

Python Programming -Unit-5 Objective Type Questions - [ Python Programming ]


Similar Materials :

R - Programming MCQs - Unit-1 - [ R-Programming ]

R - Programming MCQs - Unit-2 - [ R-Programming ]

R - Programming MCQs - Unit-3 - [ R-Programming ]

R - Programming MCQs - Unit-4 - [ R-Programming ]

R - Programming MCQs - Unit-5 - [ R-Programming ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-1 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-2 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-3 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-4 - [ FLAT ]

Formal Languages and Automata Theory (FLAT) MCQs - Unit-5 - [ FLAT ]

PPS MCQs - Unit-1 - [ PPS ]

PPS MCQs - Unit-2 - [ PPS ]

PPS MCQs - Unit-3 - [ PPS ]

PPS MCQs - Unit-4 - [ PPS ]

PPS MCQs - Unit-5 - [ PPS ]

Object Oriented Programming through Java MCQs - Unit-1 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-2 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-3 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-4 - [ OOP_JAVA ]

Object Oriented Programming through Java MCQs - Unit-5 - [ OOP_JAVA ]

Design and Analysis of Algorithms MCQs - Unit-1 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-2 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-3 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-4 - [ DAA ]

Design and Analysis of Algorithms MCQs - Unit-5 - [ DAA ]

Software Engineering MCQs - Unit-1 - [ SE ]

Software Engineering MCQs - Unit-2 - [ SE ]

Software Engineering MCQs - Unit-3 - [ SE ]

Software Engineering MCQs - Unit-4 - [ SE ]

Software Engineering MCQs - Unit-5 - [ SE ]

Data Mining MCQs - Unit-1 - [ DM ]

Data Mining MCQs - Unit-2 - [ DM ]

Data Mining MCQs - Unit-3 - [ DM ]

Data Mining MCQs - Unit-4 - [ DM ]

Data Mining MCQs - Unit-5 - [ DM ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-1 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-2 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-3 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-4 - [ COA ]

Computer Organization and Architecture (COA) Objective Question Bank-Unit-5 - [ COA ]

Data Structures Objective Type Question Bank-Unit-1 - [ DS ]

Data Structures Objective Type Question Bank-Unit-2 - [ DS ]

Data Structures Objective Type Question Bank-Unit-3 - [ DS ]

Data Structures Objective Type Question Bank-Unit-4 - [ DS ]

Data Structures Objective Type Question Bank-Unit-5 - [ DS ]

Database Management System Objective Type Question Bank-Unit-1 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-2 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-3 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-4 - [ DBMS ]

Database Management System Objective Type Question Bank-Unit-5 - [ DBMS ]