wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python

Total questions: 82

Worksheet time: 40mins

Name
Class
Date
1.
What is python named after
a)
The snake
b)
Television show called Monty Python
2.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
3.
Python identifies blocks of code by
a)
BEGIN and END keywords
b)
{ and }
c)
aligning up the starts of lines (indentation)
d)
guessing
4.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
5.

people = ["John", "Rob", "Bob"]

print (people[-1])

what would this result be?

a)
John
b)
Rob
c)
Bob
6.
To create a newline at the end of prompt, you can use which of the following expressions?
a)
\new
b)
\n
c)
\break
d)
\return
7.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
8.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
9.
What extension must you add to the end of a file when saving?
a)
.xlsx
b)
.pptx
c)
.docx
d)
.py
10.
What will the output be from the following code?
print(3*4+5)
a)
27
b)
17
c)
12
d)
SyntaxError
11.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

12.

What is the output?

a)

True

b)

False

c)

condition1

d)

condition2

13.

Find T ?

T=144 / 2 + 5 * 9 - ( 8 -3 )

a)

106

b)

688

c)

112

d)

684

14.

Find the Output:

Item = {"ECE" , "CSE" , "EEE" , "CIVIL"}

Item.add (2,"MECH")

print(Item)

a)

{ "ECE" , "MECH" , "CSE" , "EEE" , "CIVIL" }

b)

{ "ECE" , "CSE" , "MECH" , "EEE" , "CIVIL" }

c)

{ "ECE" , "CSE" , "EEE" , "CIVIL" }

d)

{ "ECE" , "CSE" , "EEE" ,"MECH" , "CIVIL" }

15.

Find the Output ?

A = "Anand Institute of higher technology"

print ( A[-5:7]

a)

_Institute of higher techn

b)

nstitute of higher technol

c)

d Institute of higher techn

d)

Institute of higher techno

16.

def.number (r1 , r2)

sum = r1 / r2

return sum

a = number (r2 = 15 , r1 = 10)

a)

2 / 3

b)

3 / 2

c)

error

d)

2

17.

what is the output of the following code ?

var1 = 1

var2 = 2

var3 = "3"


print (var + var2 var3)

a)

Error. Mixing operators between numbers and strings are not supported

b)

6

c)

33

d)

123

18.

Which of the following function convert a string to a float in python ?

a)

float(X)

b)

int(x[,base])

c)

long(X[,base])

d)

str(X)

19.

what is the output of the following programing ?

X = [ 'ab' , 'cd' ]

for i in X:

i.upper()

print (x)

a)

[ 'AB' , 'CD' ]

b)

[ 'ab' , 'cd' ]

c)

[ AB , CD ]

d)

ERROR

20.

find p ?

p = ( 35 , 46 , 73 , 21 )

p.append( -2 , 24 )

print (p)

a)

( 35 , 46 , 73 , 24 , 21 )

b)

error

c)

( 35 , 46 , 24 , 73 , 21 )

d)

( 35 , 24 , 73 , 21 )

21.

what will be the output of the following python code snippet ?

not (10 < 20) and not (10 > 30 )

a)

TRUE

b)

FALSE

22.

Find the output ?

a = True

b = False

c = False

if a or b and c :

print "INFYTQ"

else:

print "infytq"

a)

infytq

b)

INFYTQ

c)

ERROR

23.

Which of the following are true for objects of Python’s set type:

a)

The order of elements in a set is significant.

b)

A given element can’t appear in a set more than once.

c)

Sets are mutable.

d)

A set may contain elements that are mutable.

24.

What will be the output of the following Python code? *

x={1,3,5}

y={2,4,6}

x+y

a)

{1,3,5,2,4}

b)

{1,3,5,2,4,6}

c)

Error as the duplicate item 6 is present in both sets

d)

Error as unsupported operand type(s) for +: 'set' and 'set'

25.

Which of the following functions will return the symmetric difference between two sets, x and y? *

a)

x | y

b)

x ^ y

c)

x & y

d)

x – y

26.

What will be the output of the following Python code?

x = {4,7,8,8,9}

print(x)

a)

{4, 7, 9}

b)

{8, 9, 4, 7}

c)

{4, 7, 8, 8, 9}

d)

Error

27.

Which of the following statements is used to create an empty set?

a)

{ }

b)

set()

c)

[ ]

d)

( )

28.

What will be the output of the following Python code?

x = {6,5}

y = {2,3,5,6}

x<y

a)

{1,2}

b)

True

c)

False

d)

Invalid operation

29.

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

a)

remove

b)

pop

c)

discard

d)

dispose

30.

Which of these about a set is not true?

a)

Mutable data type

b)

Allows duplicate values

c)

Data type with unordered values

d)

Immutable data type

31.

If x={5,6,7,8}, which of the following statements is false?

a)

print(len(x))

b)

print(min(x))

c)

x.remove(5)

d)

x[2]=45

32.

Which of the following is not the correct syntax for creating a set?

a)

set([[1,2],[3,4]])

b)

set([1,2,2,3,4])

c)

set((1,2,3,4))

d)

{1,2,3,4}

33.

In Python, a variable must be declared before it is assigned a value:

a)

False

b)

True

c)

None

34.

Which of the following statements assigns the value 100 to the variable x in Python:

a)

x := 100

b)

x = 100

c)

x << 100

d)

let x = 100

e)

x <- 100

35.

In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:

a)

False

b)

True

c)

None

36.

Consider the following sequence of statements:


n = 300

m = n


Following execution of these statements, Python has created how many objects and how many references?

a)

Two objects, two references

b)

One objects, two references

c)

One objects, one references

d)

Two objects, one references

37.

What Python built-in function returns the unique number assigned to an object:

a)

ref( )

b)

identity( )

c)

id( )

d)

refnum( )

38.

Which of the following are valid Python variable names:

a)

router66

b)

ver1.3

c)

Age

d)

return

e)

home_address

39.

You are reading Python code, and these statements appear scattered in different locations throughout the code:


employeenumber = 4398

.

.

.

EmployeeNumber = 4398

.

.

.

employeeNumber = 4398

a)

These statements refer to different variables.

b)

These statements refer to the same variable.

40.

Which of the following styles does PEP8 recommend for multi-word variable names:

a)

DistanceToNearestTown (Pascal Case)

b)

distanceToNearestTown (Camel Case)

c)

distance_to_nearest_town (Snake Case)

d)

None

41.

Which of the following are Python reserved words (keywords):

a)

None

b)

default

c)

class

d)

goto

e)

and

42.

Find the output of the code:

# abc.py

def func(n):

return n + 10


func('Hello')

(a)  

43.

Find the output of the code:


nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']

print nameList[1][-1]

(a)  

44.

Find the output of the code:

for i in range(2):

print i


for i in range(4,6):

print i

a)

0,1,4,5

b)

0,1,2,4,5,6

c)

0,1,2,3,4,5,6

d)

2,4,6

45.

Find the output of the code:

geekCodes = [1, 2, 3, 4]

geekCodes.append([5,6,7,8])

print len(geekCodes)

a)

4

b)

5

c)

6

d)

8

46.

Find the output of the code:

check1 = ['Learn', 'Quiz', 'Practice', 'Contribute']

check2 = check1

check3 = check1[:]

check2[0] = 'Code'

check3[1] = 'Mcq'

count = 0

for c in (check1, check2, check3):

if c[0] == 'Code':

count += 1

if c[1] == 'Mcq':

count += 10

print count

a)

10

b)

11

c)

12

d)

13

47.

What is the output of the code:

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

print d1 > d2

a)

True

b)

False

c)

Not applicable

48.

Find the output of the code:

D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}

D['1'] = 2

print(D[D[D[str(D[1])]]])

a)

2

b)

3

c)

'2'

d)

Key error

49.

Find the output of the code:

D = dict()

for i in range (3):

for j in range(2):

D[i] = j

print(D)

a)

{0: 0, 1: 0, 2: 0}

b)

{0: 1, 1: 1, 2: 1}

c)

{0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}

d)

TypeError: Immutable object

50.

Find the output of the code:

List = [True, 50, 10]

List.insert(2, 5)

print(List, "Sum is: ", sum(List))

a)

[True, 50, 10, 5] Sum is: 66

b)

[True, 50, 5, 10] Sum is: 65

c)

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’

d)

[True, 50, 5, 10] Sum is: 66

51.

Find the output of the code:

L = list('123456')

L[0] = L[5] = 0

L[3] = L[-2]

print(L)

a)

[0, ‘2’, ‘3’, ‘4’, ‘5’, 0]

b)

[‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’]

c)

[‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]

d)

[0, ‘2’, ‘3’, ‘5’, ‘5’, 0]

52.

Which of the following are true of Python lists?

a)

A list may contain any type of object except another list

b)

A given object may appear in a list more than once

c)

All elements in a list must be of the same type

d)

These represent the same list:

['a', 'b', 'c']

['c', 'a', 'b']

e)

There is no conceptual limit to the size of a list

53.

Assume the following list definition:


>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']


Several short REPL sessions are shown below. Which display correct output?

a)

>>> print(a[-6])

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

IndexError: list index out of range

b)

>>> a[:] is a

True

c)

>>> print(a[4::-2])

['quux', 'baz', 'foo']

d)

>>> print(a[-5:-3])

['bar', 'baz']

e)

>>> max(a[2:4] + ['grault'])

'qux'

54.

List a is defined as follows:


a = [1, 2, 3, 4, 5]


Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:

a)

a[2] = []

b)

a[2:2] = []

c)

a[2:3] = []

d)

del a[2]

e)

a.remove(3)

55.

Consider the following nested list definition:


x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']


A schematic for this list is shown above:


What is the expression that returns the 'z' in 'baz'?

a)

x[1][2][1]

b)

x[1][2][1][2]

c)

x[1][2][2]

d)

x[1][1][2]

56.

List a is defined as follows:


a = [1, 2, 3, 4, 5]


Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:

a)

a[2:3] = []

b)

a[2] = []

c)

a.remove(3)

d)

a[2:2] = []

e)

del a[2]

57.

List a is defined as follows:


a = ['a', 'b', 'c']


Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:

a)

a += ['d', 'e']

b)

a[-1:] = ['d', 'e']

c)

a += 'de'

d)

a.append(['d', 'e'])

e)

a[len(a):] = ['d', 'e']

58.

You have a list a defined as follows:


a = [1, 2, 7, 8]


Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].

a)

a[2:2] = [3, 4, 5, 6]

b)

a[1:2] = [3, 4, 5, 6]

c)

a[2:3] = [3, 4, 5, 6]

d)

a[3:5] = [3, 4, 5, 6]

59.

Suppose you have the following tuple definition:


t = ('foo', 'bar', 'baz')


Which of the following statements replaces the second element ('bar') with the string 'qux':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

It’s a trick question—tuples can’t be modified.

60.

Write Python code to create a tuple with a single element, the string 'foo', and assign it to a variable called t.

(a)  

61.

Consider this assignment statement:


a, b, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)[1::3]


Following execution of this statement, what is the value of b:

a)

5

b)

4

c)

3

d)

6

e)

7

62.

Assume x and y are assigned as follows:


x = 5

y = -5


What is the effect of this statement:


x, y = (y, x)[::-1]

a)

The values of x and y are swapped

b)

The values of x and y are unchanged

c)

Both x and y are -5

d)

Both x and y are 5

63.

Who is the founder of Python Programming Language?

a)

Rasmus Ganilo

b)

Dennis Ritchie

c)

Guido van Rossum

d)

James Gosling

64.

File extension of Python program is ______

a)

.py

b)

.p

c)

.pyx

d)

.pyy

65.

List index begins with _________.

a)

0

b)

1

c)

-1

d)

-2

66.

Which method adds element at the end of the List?

a)

add()

b)

append()

c)

new()

d)

insert()

67.

_________________is an anonymous function.

a)

User Defined

b)

Default

c)

Lambda

d)

Reserved

68.

____________ is a collection which is unordered, changable and indexed.

a)

Dictionary

b)

List

c)

Tuple

d)

Set

69.

Python 3.7 was released on

a)

June 2016

b)

June 2017

c)

June 2018

d)

June 2019

70.

IN and NOT IN are membership operators.

a)

TRUE

b)

FALSE

71.

IS is an Identity Operator.

a)

True

b)

False

72.

List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]

print(List.pop()) What willbe the answer?

a)

2.3

b)

2.5

c)

1.054

d)

4.445

73.

What will be the anser for this code?

a)

120

b)

650

c)

225

d)

400

74.

In Python_____________ are written with round brackets

a)

tuples

b)

dictionary

c)

list

d)

set

75.

a=(1,2,3,2,4,5,2)

a.count(2)

What will be the answer?

a)

2

b)

1

c)

3

d)

4

76.

Keys and Values are related to ________

a)

tuple

b)

dictionary

c)

list

d)

set

77.

The def keyword, along with the function name is used to define the __________

a)

file

b)

block

c)

function

d)

variable

78.

_______is used as a dummy place holder whenever a syntactical requirement of a certain programming element is to be fulfilled without assigning any operation

a)

Pass

b)

Break

c)

While

d)

Goto

79.

What will be the Output?

a)

1

b)

2

c)

3

d)

4

80.

List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1]

print(List.count(1))

What will be the output?

a)

1

b)

2

c)

3

d)

4

81.

x = lambda a, b : a * b

print(x(5, 8))

What will be the output?

a)

35

b)

13

c)

40

d)

45

82.

____________does not hold duplicate values and is unordered.

a)

Set

b)

Tuple

c)

Dictionary

d)

List