0% found this document useful (0 votes)
4 views40 pages

Python QB

The document consists of a series of questions and statements related to Python programming, covering topics such as data types, functions, inheritance, and exception handling. Each question prompts the reader to select the correct or incorrect statement, identify outputs of code snippets, or understand Python concepts. The format suggests it is likely a quiz or assessment tool for evaluating knowledge of Python programming.

Uploaded by

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

Python QB

The document consists of a series of questions and statements related to Python programming, covering topics such as data types, functions, inheritance, and exception handling. Each question prompts the reader to select the correct or incorrect statement, identify outputs of code snippets, or understand Python concepts. The format suggests it is likely a quiz or assessment tool for evaluating knowledge of Python programming.

Uploaded by

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

1 1 R

What do we use to define a block of code in Python


language?

2 1 R

Select the incorrect statement for Python.


3 1 U

Which one of the following is the correct way of declaring


and initializing a variable, x with the value 17?

4 1 U

Which of the following statement is False?

5 1 R

l = [ 4, 8, 9, 2.6, 5 ] is a type of which data type in


python?

6 1 R

All keywords in Python are in ____

7 1 U

In which data type, indexing is not valid?


In which data type, indexing is not valid?

Select the correct option related Statement1 and


8 1 U
Statement2.
Statement1- Comments can be used to make the code
more readable.
Statement2- Comments can be used to prevent
execution when testing code.

9 2 U

Which of the following types of loops are not supported


in Python?

10 2 U

Select the statement which is False

11 2 U

Does python have switch case statement?


12 2 U

The ________ statement is a null operation.

13 2 U

the order of execution of the statements in a program is


know as____________

14 2 A

What is the output of print(2 ** 3 ** 2)

15 1 U

Which of these in not a core datatype?

16 3 U

What is the output when we execute list(“hello”)?

17 3 R

How to define an empty list in python.


18 3 R

In order to store values in terms of key and value we use


that core data type in python?

19 Write the output of the following code : 3 U

L=[“Amit”,”Sumit”,”Naina”]
L1=[“Sunil”]
print(L + L1)

20 3 R

A tuple is a collection of objects which ____ and _________.

Select all the correct options to remove “Orange” from


21 3 A
the set.

sampleSet = {"Yellow", "Orange", "Black"}

Statement A- Tuple items are indexed, the first item has


22 3 A
index [0], the
Statement second
B-Sets itemhave
cannot has two
index [1] . with the same
items
value.

Select the option for Statement A and Statement B.

23 3 R

Choose the correct option.


24 4 R

If return statement is not used inside the function, the


function will return:

25 4 R

What are the advantages of functions in python?

26 3 U

Which of the following isn’t true about dictionary keys?

27 4 R

Select the correct statement for module

Suppose a function called add() is defined in a module


28 4 A
called adder.py.
Which of the following code snippets correctly show how
to import and use the add() function?
29 4 R

The help statement display ___ from a module.

30 4 A

Which file must be a part of a folder to be used as a


Python package?

31 4 U

Which of the following is not a valid namespace?

32 4 U

Where is function defined?

Statement 1 :You can choose to import only parts from a


33 4 A
module, by2using
Statement :You the
can from keyword.
create an alias when you import a
module, by using the as keyword.
Select the correct option for statement 1 and statement
2.
Choose the correct function declaration of sample() so
34 that we can execute the following function call 4 A
successfully.
sample(25, 75, 55)
sample(10, 20)

35 4 U

What are the two main types of functions?


What are the two main types of functions?

36 5 U

The __init__() function is a _________

Parent class is the class being inherited from, also called


37 5 A
_________.
The class that inherits from another class, also called
_____________.

38 Statement 1: 5 A
The child's __init__() function overrides the inheritance of
the parent's __init__() function.
Statement 2:
super() function will make the child class inherit all the
methods and properties from its parent.
Select the correct option related to statement1 and
statement 2.

39 5 U

What is getattr() used for?

40 5 U

Which of the following statements is false about


inheritance?
41 5 U

The main working of data hiding is that it combines the


____and ________ into a single unit to conceal data within
a class.

How many objects and reference variables are there for


42 5 U
the given Python code?

class A:
print("Inside class")
A()
A()
obj=A()

43 5 A

Which of the following statements is not true

Statement A: Overriding means changing behaviour of


44 Statement B: A class in which one or more methods are 5 A
methods of derived class methods in the base class.
only implemented to raise an exception is called an
abstract class.
State the correct option for A and B.
45 6 U

Which of the following is not an exception handling


keyword in Python ?

46 6 A

Select statement which will read 5 characters from a


file(file object ‘f’)?

47 6 U

Which function open file in python?

48 6 A

select the correct statement which will return one line


from a file (file object is ‘f’)
49 6 U

Select which function is related to file handling.

50 6 U

Which block lets you test a block of code for errors?

51 6 A

Select the correct statement for Exception Handling

52 output of following code. 3 U

mytuple = ("apple", "banana", "cherry")

print(type(mytuple))

53 3 A

which method is correct to update tuple.

54 input is: ("apple", "banana", "cherry") 3 A


54 3 A

output is: ('apple', 'banana', 'cherry', 'apple', 'banana',


'cherry')

what code require

55 1 R

Is Python case sensitive when dealing with identifiers?

56 1 R

Select the correct example of complex datatype in


Python

57 1 U

Which of the following is not valid variable name in


Python?

58 1 R

. What is the extension of the python file?

59 A. Python is an Object-Oriented Programming Language. 1 U

B. Python was developed by Guido van Rossum.

Select the correct statement for A and B.


60 1 U

Which of the following statements is true?

61 1 R

Which of the following character is used to give single-


line comments in Python?

62 1 R

Select the reserved keywords in python

63 1 R

what is the maximum possible length of an identifier?

64 1 U

Python allows you to assign a single value to multiple


variables simultaneously.
65 2 U

Following which method is used to concatenate the list.

66 What will be the output of following Python code? 3 A

list1=[1,3,4,2]
x=list1.pop(2)
print(set([x]))

67 What will the below Python code do? 3 U

set1={"a",3,"b",3}
set1.remove(3)

68 6 A

If there is an error in opening a file, which exception is


raised ?

69 5 A

Which of the following is not a type of inheritance?

70 5 A

In python, what is method inside class?


71 5 A

What is Instantiation in terms of OOP terminology?

72 4 U

What is a variable defined outside a function referred to


as?

73 4 A

How is a function declared in Python?

74 6 A

Which function is used to read all the characters?

75 Select output of following code snippet: 2 A

y = 10
x = y += 2
print(x)

76 Select output of following code: 2 A

a = [10, 20]
b=a
b += [30, 40]
print(a)
print(b)

77 Select output of following code snippet: 2 A

a=7
77 2 A

b=4
c=5
print(a & b)
print(a & c)
print(b & c)

78 Select output of following code: 2 A

count = 0
while(True):
if count % 3 == 0:
print(count, end = " ")
if(count > 15):
break;
count += 1

79 2 A

Select correct option for ‘break’ statement:

80 Select correct statement for tuples in python: 3 U

Statement 1: Tuples have ordered items

Statement 2: Tuple are mutable

81 Select properties of python dictionaries: 3 U

(i) Changeable
81 3 U

(ii) Allows duplicates

82 4 A

Select correct function header in python:

83 Select output of following code: 6 A

try:
print(x)
except:
print(""An exception occurred"")

84 1 R

Who developed Python Programming Language?

85 1 R

Which of the following is the correct extension of the


Python file?

86 1 R

Which one of the following is not a keyword in Python


language?
87 1 U

To add a new element to a list we use which Python


command?

88 1. i = 0 2 U
2. while i < 3:
3. print(i)
4. i += 1
5. else:
6. print(0) What will be the output of this
statement?

89 3 A

What happens when '2' == 2 is executed?

90 4 R

How many keywords present in the python programming


language?

91 What will be the output of the following Python code? 3 U

1. def cube(x):
2. return x * x * x
3. x = cube(3)
4. print x

92 1. mytuple1=(5, 1, 7, 6, 2) 2 U
2. mytuple1.pop(2)
3. print(mytuple1)

What will be the output of this program?


93 4 U

Parent class is the class being inherited from, also


called?

94 4 U

__________function that will make the child class inherit


all the methods and properties from its parent

95 5 U

Suppose B is a subclass of A, to invoke the __init__


method in A from B, what is the line of code you should
write?

96 my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 5 U
Which element will be printed with the following comma

print my_list[-1]
97 4 U

To open a file c:\scores.txt for reading, we use


_____________

98 4 A

To read the entire remaining contents of the file as a


string from a file object infile, we use ____________

99 5 R

Which function open file in python

100 4 U

EOF stands for _________________

101 4 R
Select the correct output of the following code
optionb

None of
Brackets Indentation Key
these

optiond

Python runs on
an interpreter
Python can be
system,
treated in a
Python can be meaning that
procedural
used on a code can be
way, an None of
server to executed as
object- these
create web soon as it is
oriented way
applications. written. This
or a functional
means that
way.
prototyping can
be very quick.
optionc

int x
int x=17 x=17 declare x=17

x=17

optiond

Data type of
variable name Variable
variable Variable name
can contain name can
names should can begin with
both letters begin with
not be underscore.
and numbers. number.
declared.

optionb

None of
Tuple List Set
these

optiond

None of the
lower case UPPER CASE Capitalized
mentioned

optionb

Class Dictionary String List


Class Dictionary String List

optionb
Statement1 Statement1 Statement1 Statement1
true and true and false and false and
Statement2 Statement2 Statement2 Statement2
false true false true

optionb

None of the
for do-while while
mentioned

optionc

While loop is
used when While loop is
multiple used when
for loop can
statements multiple
Loops are used be used to
are to statements are
to perform iterate
executed to executed
certain tasks through the
repeatedly repeatedly until
repeatedly. elements of
until the given the given
lists.
condition condition
becomes becomes False.
True.

optiona

Python has
switch
None of the
0 1 statement but
mentioned
we can not use
it.
optionb

break pass exit return

optiona

None of the
flow of control selection Iteration
mentioned

optionb

64 512 16 32

optiond

Lists Tuples Dictionary Class

optionb

[‘h’, ‘e’, ‘l’, ‘l’,


[‘hello’] [‘llo’] [‘olleh’]
‘o’]

optiona

colours = [ ] colours = ( ) colours = { } colours = <>


optionb

List Dictionary Class Tupple

optionb
[‘Amit’ ,
[‘Amit’ , ‘Sumit’
‘Sumit’ , List can not none of the
, ‘Naina’ ,
‘Naina’ , concatenate mentioned
[‘Sunil’]]
‘Sunil’]

optiona

ordered ,immut unordered ,un ordered ,change unordered ,m


able changeable able utable

optionb
sampleSet.dis
sampleSet.pop( del sampleSet None of the
card("Orange"
"Orange") ["Orange"] mentioned
)

optionc
Statement A is Statement A is Statement A is Statement A
false and false and true and is true and
Statement B is Statement B is Statement B is Statement B
false true true is false

optionc

a tuple can
a tuple can
a tuple can a tuple can contain
contain both
contain only contain only either string
integers and
integers as its strings as its or integer but
strings as its
elements. elements. not both at a
elements.
time.
optiona

Arbitary
None Null 0
value

optiond

Decomposing
Improving Reducing
complex All of the
clarity of the duplication of
problems into mentioned
code code
simpler pieces

optionc
When
duplicate
More than one keys
Keys must be Keys must be
key isn’t encountered,
immutable integers
allowed the last
assignment
wins

optiond

The module can


To create a
we can use contain
module just
the module, functions,
save the code All of the
by using the variables of all
you want in a mentioned
import types (arrays,
file with the file
statement. dictionaries,
extension .py
objects etc.)

import add from Math1 from adder


import adder optionb
from adder import add import add
result = result =
result = add(2, result = add(2,
adder.add(2, adder.add(2,
3) 3)
3) 3)
optiond

constants functions classes docstrings

optionb

__module.py_
package.py __init__.py __package__.py
_

optionc

Global Built-in Public Local


namespace namespace namespace namespace

optiond
Another All of the
Module Class
function mentioned

optionb
Statement 1 is Statement 1 is Statement 1 is Statement 1
true and true and false and is false and
statement 2 is statement 2 is statement 2 is statement 2
false true false is true

optiona
No, it is not
def def sample(-
possible in def sample(null)
sample(*data) 1)
Python

optionb

Built-in
System function & Custom
User function
function User defined function
function
System function & Custom
User function
function User defined function
function

optiona

initilized
constructor destructor method
method

optionb
overloading
derived class base class and object and
and
and base class derived class method
overriding

optionc

Statement 1 is Statement 1 is Statement 1 is Statement 1


false and true and true and is false and
Statement 2 is Statement 2 is Statement 2 is Statement 2
false. false. true. is true.

optionc

To check if an To access the


To delete an To set an
attribute attribute of the
attribute attribute
exists or not object

optionc

Private
Protected Inheritance is
The inheriting members of a
members of a one of the
class is called class can be
class can be features of
a subclass inherited and
inherited OOP
accessed
optionc

variable and inheritance data and data and


value and data functions module

optiond

3 and 3 2 and 1 3 and 2 3 and 1

optionc

When
invoking the
The value of a constructor
A non-private A derived private variable from a
method in a class is a in the subclass, the
superclass can subset of superclass can constructor
be overridden. superclass. be changed in of superclass
the subclass. is
automatically
invoked.

optiond
Statement A is Statement A is Statement A is Statement A
True and True and False and is False and
Statement B is Statement B Statement B is Statement B
False is True False is True
optionc

try except accept finally

optiona

None of the
f.read(5) f.read() f.reads(5)
above

optiona

All of the
open() new() Opens()
mentioned

optionc

f.read( ) f.readlines( ) f.readline( ) f.line( )


optiond

All of the
open() close() read()
mentioned

optiona

None of the
try except finally
mentioned

optiond

The finally
To throw (or block, if
The try block
raise) an specified, will
lets you test a All of the
exception, use be executed
block of code mentioned.
the raise regardless if the
for errors.
keyword. try block raises
an error or not.

optionb

<class
< 'tuple'> <class 'string'> string
'tuple'>

thistuple = thistuple =
x = ("apple",
("apple", ("apple",
"banana", optiond
"banana",
y = "banana",
y =
"cherry")
y = list(x) "cherry")
("orange",) "cherry")
list(thistuple)
y.remove("appl
y[1] = "kiwi" thistuple += y
e")
thistuple = All of the
x = tuple(y)
print(thistuple tuple(y) mentioned
)
print(x)
fruits = fruits = fruits1 = fruits =
("apple", ("apple", ("apple", ("apple",
optionb
"banana",
mytuple = "banana",
mytuple = "banana",
mytuple = fruits "banana",
mytuple = 2 -
"cherry")
fruits1 * 2 "cherry")
fruits * 2 "cherry")
*2 "cherry")
fruits **
optionb

print(mytuple
print(mytuple) print(mytuple) print(mytuple)
)

optiona

Machine None of the


Yes No
dependent above

optiond

All of the
3 + 2j -100j 5j above are
correct

optiond

_var var_name var11 11var

optionb

None of the
.p .py .python
above

optionb

A is true and B A is true and A is false and B A is false and


is false B is true is false B is true
optiond

Python is a
Python is an Python is an
high level All of the
interpreted object-oriented
programming above
language. language.
language.

optionb

// # ! /*

optiond

All of the
else import raise
above

optiona

31 character 32 character 63 character 88 character

optiona

Depend upon All of the


Yes No
machine above
optiond

All of the
+ Append extend
mentioned

optiond

{1,3,4} B. {1,3,2} {2} {4}

optionb
It removes It removes only
It removes No such
element with the first
element 3 function
index position occurance of 3
from set1 exists for set
3 from set1 from set1

optionb

IndexError IOError ImportError TypeError

optiona

Double-level Multi-level Single-level Multiple

optiond

attribute object argument function


optiond

Deleting an Modifying an Copying an Creating an


instance of instance of instance of instance of
class class class class

optionb

global automatic
local variable static Variable
variable variable

optionc
declare
def function def declare
function
function_name( function_name() function_nam
function_nam
): : e():
e():

optiona

Readcharacter
Read() Readall() Readchar()
s()

optiond

10 12 14 Syntax error

[10, 20, 30,


[10, 20, 30, 40] [10, 20] [10, 20] optiona
[10, 20, 30, 40]
[10, 20, 30, 40] [10, 20]
40]
[10, 20]

4 4 5 4 optiona

5 4 5 5
optiona

4 4 5 5

optionc

Logical error
causing
0 1 2 …. 15 0 3 6 9 12 15 0 3 6 9 12
infinite
looping

optiona

If you are using


If you are
a nested
using nested
loop(i.e., one
loops(i.e., one
loop inside Break Break
loop inside
another loop), statement statement
another loop),
the break terminates the breaks the
the break
statement will program compilation
statement will
stop the execution process.
stop the
execution of
execution of
the innermost
the outer loop.
loop.

optionc
Statement 1 is Statement 1 is Statement 1 is Statement 1
True and False and True and is False and
Statement 2 is Statement 2 is Statement 2 is Statement 2
True. True. False. is False .

optiona

Neither (i)
(i) (ii) (i), (ii)
nor (ii)
optiona

Neither (i)
(i) (ii) (i), (ii)
nor (ii)

optionc

def fun(a = 2, def fun(a = 2, def fun(a, b = 2, def fun(a, b,


b = 3, c) b, c = 3) c = 3) c = 3, d)

optionb

An exception None of the


x Syntax error
occurred above

optionc

Wick van Rasmus Guido van


Niene Stom
Rossum Lerdorf Rossum

optionc

.python .pl .py .p

optionb

pass eval assert nonlocal


optionc

list1.addLast(5
list1.addEnd(5) list1.append(5) list1.add(5)
)

optionc

1. 0 1 012 0120 0123

optiona

ValueError TypeError
0 1
occurs occurs

optiona

32 64 33 27

optionc

9 3 27 30

optionc

None of the
51762 No output AttributeError
these
optiond

derived class Child class Hybrid class base class

optionc

self __init__() super pass

optiona

A.__init__(self) B.__init__(self) A.__init__(B) B.__init__(B)

optionb

8 9 0 1
optionb

infile =
infile = infile =
infile = open(file =
open(“c:\ open(“c:\\
open(file = “c:\ “c:\\
scores.txt”, scores.txt”,
scores.txt”, “r”) scores.txt”,
“r”) “r”)
“r”)

optionb

infile.readline
infile.read(2) infile.read() infile.readline()
s()

optiona
None of the
open( ) new( ) Open( )
mentioned

optiona

End of File End off File End on File End or File

Move file Move file Move file


Move file
pointer five pointer five pointer five optiona
pointer five
characters characters characters
characters
ahead from the ahead from behind ahead
behind from the
current the beginning from the end
current position.
position. of a file. of a file.

You might also like