0% found this document useful (0 votes)
33 views8 pages

PP Mid II QB Objective Final

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

PP Mid II QB Objective Final

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MALLA REDDY ENGINEERING COLLEGE (AUTONOMOUS)

I B.Tech. II Semester (MR22) II Mid Question Bank 2023-24 (objective)


Subject: Python Programming (C0504) Branch: CSE, IT,CSE(AIML, DS, IOT), CSIT, AIML
Name of the Faculty:Dr. P. Raghunadh
S.No. Questions Ans

MODULE-III
1 What is setattr() used for? B
a)To access the attribute of the object b)To set an attribute
c)To check if an attribute exists or not
d)To delete an attribute

2 What is getattr() used for? A

a)To access the attribute of the object


b)To delete an attribute
c)To check if an attribute exists or not
d)To set an attribute

3 What will be the output of the following Python code? B


class change:
def __init__(self, x, y, z):
self.a = x + y + z
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
a)6 b)7 c)Error d)0

4 What are the dunder(magic methods) in python ? B


a)Methods that start with a double underscore b)Methods that start and end with a double underscore
c)Methods that start with a single underscore d)Methods that start and end with single underscore

5 The __add__ method is ________ C


a)Return addition of two numbers b)Overloads + Operator
c)Should be overridden to overload + operator d)B and C

6 In order to overload == operator, which magic method must be overriden ? C


a)__comp__() b)__equal__() c)__eq__() d)__ne__()

7 What is delattr(obj,name) used for? B


a)To print deleted attribute b)To delete an attribute
c)To check if an attribute is deleted or not d)To set an attribute

8 What will be the output of the following Python code? A


class stud:
def __init__(self, roll_no, grade):
self.roll_no = roll_no
self.grade = grade
def display (self):
print("Roll no : ", self.roll_no, ", Grade: ", self.grade)
stud1 = stud(34, 'S')
stud1.age=7
print(hasattr(stud1, 'age'))
a)True b)False c)Error as age isn’t defined d)7

9 Why does the name of local variables start with an underscore discouraged? C
a)To identify the variable b)It confuses the interpreter
c)It indicates a private variable of a class d)None of these

10 Default Access specifier in Python A


a)Public b)Private c)Protected d)None of these

11 Which of the following statements can be used to check, whether an object “obj” is an instance of class A or C
not?
a)obj.isinstance(A) b)A.isinstance(obj) c)isinstance(obj, A) d)isinstance(A, obj)

12 What will be the output of the following Python code? C


class Demo:
def __init__(self):
self.a = 1
self.__b = 1

def display(self):
return self.__b

obj = Demo()
print(obj.a)
a)The program has an error because there isn’t any function to return self.a
b)The program has an error because b is private and display(self) is returning a private member
c)The program runs fine and 1 is printed
d)The program has an error as you can’t name a class member using __b

13 What will be the output of the following Python code? class Demo: D
def __init__(self):
self.a = 1
self.__b = 1

def display(self):
return self.__b

obj = Demo()
print(obj.__b)
a)The program has an error because there isn’t any function to return self.a
b)The program has an error because b is private and display(self) is returning a private member
c)The program runs fine and 1 is printed
d)The program has an error because b is private and hence can’t be printed

14 Methods of a class that provide access to private members of the class are called as ______ and ______ A
a)getters/setters b)__repr__/__str__ c)user-defined functions/in-built functions d)__init__/__del__

15 The class has a documentation string, which can be accessed via? D


a)ClassName b)ClassName __doc__ c)__doc__ d)ClassName.__doc__

16 "What will be the output of the following Python code? class A: C


@staticmethod
def a(x):
print(x)
A.a(100)"
a)Error b)Warning c)100 d)No output
17 The ______ symbol along with the name of the decorator function can be placed above the definition of the C
function to be decorated works as an alternate way for decorating a function.
a)# b)$ c)@ d)&
18 Which of the following statements is true? D
a)We cannot chain multiple decorators in Python
b)Decorators don’t work with functions that take parameters
c)The @ symbol doesn’t have any use while using decorators
d)None of the above
19 Which of the following declarations is incorrect? D
a)_x = 2 b)__x = 3 c)_xyz__ = 5 d)None of these
20 Which of the following words cannot be a variable in python language? C
a)_val b)val c)try d)_try_
21 "Study the following program: D
class Teacher:
def __init__(name, id_no, age):

name.id_no = id_no

name.age = age
teac = Teacher(5, 25)
Which of the following statements is incorrect regarding this program?"
a) A constructor has been given in this program
b)id_no and age are called the parameters
c)The "teac" is the reference variable for the object Teacher(5, 25)
d)None of the these

22 What is the other name of special method? C


a)Dunder Method b)Magic Method c)Both A and B d)None of these
23 Example of protected variable: B
a)c.val b)c._val c)c.__val... d)None of these
24 ____ represents an entity in the real world with its identity and behaviour. B
a) A method b)An object c)A class d)An operator
25 _____ is used to create an object. A
a)class b)constructor c)User-defined functions d)In-built functions
MODULE-IV
26 When will the else part of try-except-else be executed?
A)alwaysB)when an exception occursC)when no exception occursD)when an exception occurs in to except C
block
27 Can one block of except statements handle multiple exception?
A) yes, like except TypeError, SyntaxError [,…]B)yes, like except (TypeError, SyntaxError) B
C)noD) none of the mentioned
28 When is the finally block executed?
A)when there is no exceptionB)when there is an exception D
C)only if some condition that has been specified is satisfiedD)always
29 Which of the following is not an exception handling keyword in Python?
C
A)tryB)exceptC)acceptD)finally
30 What will be the output of the following Python code?
try:
if '1' != 1:
raise "someError"
else: C
print("someError has not occurred")
except "someError":
print ("someError has occurred")
A)someError has occurredB)someError has not occurredC)invalid codeD)none of the mentioned
31 What will be the output of the following Python code?
C
x=10
y=8
assert x>y, 'X too small'
A)Assertion ErrorB)10 8C)No outputD)X too small
32 What will be the output of the following Python code?
lst = [1, 2, 3]
D
lst[3]
A)NameErrorB)ValueErrorC)TypeErrorD)IndexError
33 Which of the following is not a standard exception in Python?
C
A)NameErrorB)IOErrorC)AssignmentErrorD)ValueError
34
An exception is ____________
A
A)an objectB)a special functionC)a standard moduleD)a module

35 ____________exception raised as a result of an error in opening a particular file.


D
A)ValueErrorB)TypeErrorC)ImportErrorD) IOError
36 Which of the following blocks will be executed whether an exception is thrown or not?
B
A)exceptB)finallyC)elseD)assert
37 Which of the following statements is true?
A)The standard exceptions are automatically imported into Python programs
B)All raised standard exceptions must be handled in Python A
C)When there is a deviation from the rules of a programming language, a semantic error is thrown
D)If any exception is thrown in try block, else block is executed
38 Which of the following is correct?
A)An exception is an error that occurs at run time
B)A syntax error is also an exception A
C)An exception is used to exclude a block of code in python
D)All of above
39 What is written in the try clause of a try…except statement?
A)Code that handles the exception
B)An operation which can raise an exception B
C)Both (A) and (B)
D)None of the mentioned
40 How many types of exceptions are available in Python? B
A)1 B)2 C)3 D)4
41 Exceptions are A
A)run time error B)Syntax error C)Both a and b D)None of the above
42 Which block will be executed at any condition? B
A)else B)finally C)except D)try
43 Which of the following is a generic exception? A
A)Exception B)ImportError C)EOFError D)None of the above
44 Which type of error will not interrupt the execution of a program? B
A)Syntax error B)Logic error C) Exception D)All of the above
45 Which type of error will be generated during the runtime? C
A)syntax error B)Logic error C)Exception D)All of the above
46 ZERODIVISIONERRORis C
A)syntax error B)Logic error C)Exception D)All of the above
47 If an exception is not raised within the try block, then which block is executed? C
A)try block B)except block C)else block D)All the above
48 Can one block of except statements handle multiple exceptions? A
a) yes, like except TypeError, SyntaxError [,…]
b) yes, like except [TypeError, SyntaxError]
c) no
d) none of the mentioned
49 What will be the output of the following Python code? B
def foo():
try:
return1
finally:
return2
k = foo()
print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
50 How many except statements can a try-except block have? D
a) zero
b) one
c) more than one
d) more than zero
51 ._______ makes it possible for two or more activities to execute in parallel on a single A
A )Multithreading B) Threading C) Single Threading D) Both Single Threading & Multi-threading
52 In ______ an object of type Thread in the namespace System.Threading represents and controls one thread C
.PY B).SAP C) .NET D) .EXE
53 The method will be executed once the thread’s ______ method is called. D
A) EventBegin B)EventStart C) Begin D) Start
54 Command to make thread sleep? A
A) Thread.SleepB)Thread_Sleep C) ThreadSleep D)Thread_sleep
55 An instance of class Buffer provides a threadsafe way of communication between ________ B
A) Actors B) Objects C) Locking D) Buffer
56 _______ method puts zero into the buffer. A
A) HandlePut(object o)B) HandletGet(object o) C) HandletGet() D)HandletPut()
57 . HandlePut(object o) performs what? D
a) Fixing values b) Locking c) Changing values d) Unlocking

58 In HandlePut(object o), o represents? A


a) Null b) Zero c) Empty d) Origin

59 What is HandleGet() method function? B

a) Current buffer state, with changing b) Current buffer state, without changing
c) Previous buffer state, with changing d) Previous buffer state, without changing

60 What is the result for HandleGet()? A

a) Null b) Zero c) Empty d) Origin

61 Multithreading is a mechanism for splitting up a program into several parallel activities called _________ D

a) Methods b) Objects c) Classes d) Threads

62 Each thread is a single stream of execution. B


a) False b) True

63 Multithreading on a single processor is possible with the help of _________ B

a) Threader b) Scheduler c) Method d) Divider

64 Scheduler switch threads in ________ scheduling C


a) Multilevel queue b) Priority Scheduling c) Round robin fashion d) Multilevel feedback queue scheduling

65 Thread can be created in how many ways? B

a) 1 b) 2 c) 3 d) 4
66 A
Multithreading is also called as ____________
a) Concurrency b) Simultaneity c) Crosscurrent d) Recurrent

67 Which Python library module runs a function as thread? B


A. thread
B. threading
C. both A & B
D. None

68 A single sequential flow of control within a program is ________ C


a) Process b) Task c) Thread d) Structure

69 A method that must be overridden while extending threads. A


a) run() b) start() c) stop() d) paint()

70 A thread becomes non runnable when? B


a) Its stop method is invoked b) Its sleep method is invoked
c) Its finish method is invoked d) Its init method is invoked

71 A method used to temporarily release time for other threads. A


a) yield() b) set() c) release() d) start()

72 What will be the output of the following Python code? B


for i in range(0):
print(i)
a) 0 b) no output c) error d) none of the mentioned

73 Given a function that does not return any value, What value is thrown by default when executed in shell D
a) Int b)Bool c)Void d)none

74 A method used to force one thread to wait for another thread to finish. A
a) join() b) connect() c) combine() d) concat()

75 Which of the following declarations is incorrect? D


a)_x = 2 b) __x = 3 c)__xyz__ = 5 d) None of these

76 Config() in Python Tkinter are used for C


a) destroy the widget b)place the widget
c).change property of the widget d)configure the widget
77 Correct way to draw a line in canvas tkinter ? B
a).line() b).canvas.create_line() c).create_line(canvas) d)None of the above
78 Creating line are come in which type of thing ? B
a)GUI b)Canvas c)Both of the above d)None of the above
79 Essential thing to create a window screen using tkinter python? A
a)call tk() function b)create a button c)To define a geometry d)All of the above
80 fg in tkinter widget is stands for ? A
a)foreground b)background c)foregap d)None of the above
81 For displaying multiline text, which widget can be used in tkinter? B
a) Entry b) Text c) Both A & B d)None of the above

82 For what purpose, the bg is used in Tkinterwidget ? D


"a)To change the direction of widget b)To change the size of widget
c)To change the color of widget d)To change the background of widget
83 From which keyword we import the Tkinter in program? C
a) call b) from c)import d)All of the above
84 GUI stands for C
a)Graph user interaction b)Global user interaction
c)Graphical user interface d)Graphical user interaction
85 How pack() function works on tkinter widget ? C
a)According to x,y coordinate
b)According to row and column vise
c)According to left,right,up,down d)None of the above
86 How the grid() function put the widget on the screen ? B
a)According to x,y coordinate b)According to row and column vise
c)According to left,right,up,down d)None of the above
87 How the place() function put the widget on the screen ? A
a)According to x,y coordinate b)According to row and column vise
c)According to left,right,up,down d)None of the above
88 How we import a tkinter in python program ? D
a).import tkinter b)import tkinter as t
c)from tkinter import * d)All of the above
89 How we install tkinter in system ? C
a)pip install python b)tkinter install
c)pip install tkinter d)tkinter pip install
90 In which of the following field, we can put our Button? C
a)Window b)Frame c)both A & B d)None
91 It is possible to draw a circle directly in Tkintercanvas ? C
a)Yes b)No c) No (but possible by oval) d)None of the above
92 Minimum number of argument we pass in a function to create a rectangle using canvas tkinter ? B
a)2 b)4 c)6 d)5
93 Minimum number of argument we require to pass in a function to create a line ? B
a)2 b)4 c)6 d)8
94 Screen inside another screen is possible by creating B
a)Another window b)Frames c)Buttons d)Labels
95 " title() is used for " A
a).give a title name to the window b)give a title name to the Button
c)give a title name to the Widet d)None of the above
96 "Tkinter tool in python provide the_____ programming C
a)Database b)OS commands c)GUI d)All of the above
97 To change the color of the text in the Button widget, what we use ? B
a)bg b)fg c)color d)cchng
98 "To change the property of the widget after the declaration of widget, what euse ?" B
a)mainloop() function b).config() function c)pack() function d)title() function
99 To delete any widget from the screen which function we use ? C
a)stop() b)delete() c)destroy() d)break()
100 To get the multiple line user data, which widget we use ? B
a) Entry b) Text c) Both of the above d) None of the above
101 To use the tkinter in python3,which of the following statement is used? B
A)import * B)import sys C) from tkinter import* D)from *import tkinter
102 A single line text is handled with which widget? B
A)Label B)Entry C)labelbutton D)None of the above
103 Which of the following widget is used to place the images? A
A)label B)entry C)labelbutton D)None of the above
104 Tkinter supports? B
A)command line interfacing B)GUI C) threading D)none of the above
105 The scrollbar widget can place scrollbar at? C
A)left B)right C)either a or b D)None of the above
106 Which of the following places other widgets in current window? A
A)pack() B)grid() C)place() D)None of the above
107 Which of the following places data in table structure? B
A)pack() B)grid() C)place() D)None of the above
108 What are the ways to support GUI in Python? D
A)wxPython B)JPython C)Tkinter D)All of the above
109 Frequently updated GUI support is A
A) wxPython B)JPython C)Tkinter D)All of the above
110 Which of the following is a Java based GUI? B
A)wxPython B)JPython C)Tkinter D)All of the above
111 Which of the following is a Tk interface? C
wxPython B)JPython C)Tkinter D)All of the above
112 A GUI application is created with? C
A)new() B)create() C)Tk() D)all of the above
113 Which of the following method is used for executing the events? B
A)loop() B)mainloop() C)run() D)mainrun()
114 An example of widgets is D
A)button B)canvas C)entry D)All of the above
115 For adding images in GUI, which of the following is used to represent the image? C
A)Image() B)Photo() C)PhotoImage() D)All of the above
116 For Button widget, the arguments are passes by using B
A)command line arguments B)lambda expression C)regular expression D)None of the above
117 Which of the following functions does not accept any arguments? A
A)position B)fillcolor C)goto D)setheading()
118 Which of the following functions results in an error? D
A)turtle.shape(“turtle”) B)turtle.shape(“square”) C)turtle.shape(“triangle”) D) turtle.shape(“rectangle”)
119 Which of the following are valid Tkinter widgets? D
A)Button B)Label C)Entry D)All of the above
120 Which GUI Framework is the best for Python coders? A
(A) PyQt5 (B) Tkinter (C) Kivy (D) wxPython

121 What is the main advantage of using a GUI framework in Python? A


(A) It makes it easier to create user interfaces.
(B) It makes it easier to write code.
(C) It makes it easier to debug code.
(D) It makes it easier to deploy code.

122 Which of the following is not a widget in Tkinter? D


(A) Label (B) Button (C) Entry (D) Canvas
123 Which of the following is not a layout manager in Tkinter?(D) D
(A) Pack (B) Grid (C) Place (D) Anchor
124 Tkinter tool in python provide the C
A)Database B)OS command C)GUI D)All of the above

125 Which of the following command are used to install the tkinter? A
A)Pip install Tkinter B)pip install python tkinter C)pip install tkinter python D)None of these

Course Coordinator: Dean I Yr.

You might also like