Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz BS(N), MSc, BCA

Total questions: 83

Worksheet time: 46mins

Name
Class
Date
1.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

2.

What is the output of the given code?

a)

10 20 10

b)

10

c)

20

d)

10 20

3.

What is the output of the given code?

a)

10 20 10 20

b)

10 20 10

c)

10 20 20

d)

Error

4.

Python supports variable number of parameters.

a)

True

b)

False

5.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

6.

The default return value of any function in Python is _______________.

a)

null

b)

0

c)

None

d)

Garbage value

7.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

none of the above

8.

___________ are the arguments passed to a function in correct positional order.

a)

Keyword arguments

b)

Default arguments

c)

Variable-length arguments

d)

Required arguments

e)

none of the above

9.

times is ________________ type of argument.

a)

default arguments

b)

keyword arguments

c)

positional arguments

d)

arbitrary positional arguments

e)

arbitrary keyword arguments

10.

Select the advantages of functions

a)

Modular programming

b)

Code re-usability

c)

Improving clarity of the code

d)

All the above

11.

What is the output of Following code?

List = ['spam', 2.0, 5, [10, 20]]

print(List[2])

(a)  

12.

What is the output of Following code?

cheeses = ['Cheddar', 'Edam', 'Gouda']

numbers = [42, 123]

print(cheeses, numbers)

a)

['Cheddar', 'Edam', 'Gouda'] [42, 123]

b)

[42, 123] ['Cheddar', 'Edam', 'Gouda']

c)

Compilation Error

d)

No output

13.

What is output of the following Code (Execute in Intrepreter)

cheeses = ['Cheddar', 'Edam', 'Gouda']

'Edam' in cheeses

(a)  

14.

In Python, list is mutable

a)

True

b)

False

15.

Which of the following commands will create a list?

a)

list1 = list()

b)

list1 = []

c)

list1 = list([1, 2, 3])

d)

list1 = new List()

16.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[1:2])

(a)  

17.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[2:1])

(a)  

18.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[::-1])

a)

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

b)

[1,2,3,4,5,6,7,8,9,10]

c)

Error

d)

No output

19.

What is the output of the following code?

list = [1,2,3,4,5,6,7,8,9,10]

print(list[::-3])

a)

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

b)

Compilation error

c)

[8,9,10]

d)

[10, 7, 4, 1]

20.

What is the output of the following code?

list = []

list.append(1)

list.append(2.0)

list.append("vk")

print(list)

a)

[1, 2.0, 'vk']

b)

Error

c)

['vk', 1, 2.0]

d)

No putput

21.

Tuples in Python are mutable

a)

False

b)

True

22.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

23.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

24.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

25.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')

26.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

27.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

28.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

29.

What is the output of the program above ?

a)

True

b)

False

30.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

31.

What is the output of the code above

a)

None

b)

Syntax Error

c)

-1

d)

Code doesn't compile

32.

The output of the code above is

a)

Key Error

b)

4

c)

Math

33.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

34.

What is the output of the program above

a)

e

b)

y

c)

t

d)

g

35.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

36.

What is the output of the code above

a)

[3.6, 3.7, 3.8, 4]

b)

[101, 102, 103, 104]

37.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

38.

Which of the following are valid ways to create a dictionary like this

a)
b)
c)
d)
e)
39.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
40.

What is the output of the code above

a)

3.9

b)

4

c)

Syntax error

41.

What is the output of the program above

a)

7

b)

6

c)

5

d)

9

e)

4

42.

How to fix the syntax error above ?

a)

grades.pop("Science", None)

b)

grades.pop["Science","None"]

c)

del grades["Math"]

d)

del grades["Math", None]

43.

What is the problem with the code above ?

a)

Dictionary cannot be changed during an iteration

b)

This code will run fine (without syntax errors)

c)

After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.

44.

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

45.

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}

46.

What will be the output of the following Python code?

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

print(len(nums))

a)

7

b)

Error, invalid syntax for formation of set

c)

4

d)

8

47.

What will be the output of the following Python code?

a = [5,5,6,7,7,7]

b = set(a)

def test(lst):

if lst in b:

return 1

else:

return 0

for i in filter(test, a):

print(i,end=" ")

a)

5 5 6

b)

5 6 7

c)

5 5 6 7 7 7

d)

5 6 7 7 7

48.

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

a)

{ }

b)

set()

c)

[ ]

d)

( )

49.

What will be the output of the following Python code?

>>> a={5,4}

>>> b={1,2,4,5}

>>> a<b

a)

{1,2}

b)

True

c)

False

d)

Invalid operation

50.

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

a)

print(len(a))

b)

print(min(a))

c)

a.remove(5)

d)

a[2]=45

51.

If a={5,6,7}, what happens when a.add(5) is executed?

a)

a={5,5,6,7}

b)

a={5,6,7}

c)

Error as there is no add function for set data type

d)

Error as 5 already exists in the set

52.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a+b

a)

{4,5,6,2,8}

b)

{4,5,6,2,8,6}

c)

Error as unsupported operand type for sets

d)

Error as the duplicate item 6 is present in both sets

53.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a-b

a)

{4,5}

b)

{6}

c)

Error as unsupported operand type for set data type

d)

Error as the duplicate item 6 is present in both sets

54.

What will be the output of the following Python code?

>>> a={5,6,7,8}

>>> b={7,8,10,11}

>>> a^b

a)

{5,6,7,8,10,11}

b)

{7,8}

c)

Error as unsupported operand type of set data type

d)

{5,6,10,11}

55.

What will be the output of the following Python code?

>>> s={5,6}

>>> s*3

a)

Error as unsupported operand type for set data type

b)

{5,6,5,6,5,6}

c)

{5,6}

d)

Error as multiplication creates duplicate elements which isn’t allowed

56.

What will be the output of the following Python code?

>>> a={5,6,7,8}

>>> b={7,5,6,8}

>>> a==b

a)

True

b)

False

57.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> b={5,6,7}

>>> a|b

a)

Invalid operation

b)

{3, 4, 5, 6, 7}

c)

{5}

d)

{3,4,6,7}

58.

Is the following Python code valid?

a={3,4,{7,5}}

print(a[2][0])

a)

Yes, 7 is printed

b)

Error, elements of a set can’t be printed

c)

Error, subsets aren’t allowed

d)

Yes, {7,5} is printed

59.

Which of these about a frozenset is not true?

a)

Mutable data type

b)

Allows duplicate values

c)

Data type with unordered values

d)

 Immutable data type

60.

What is the syntax of the following Python code?

>>> a=frozenset(set([5,6,7]))

>>> a

a)

{5,6,7}

b)

frozenset({5,6,7})

c)

Error, not possible to convert set into frozenset

d)

Syntax error

61.

Is the following Python code valid?

>>> a=frozenset([5,6,7])

>>> a

>>> a.add(5)

a)

Yes, now a is {5,5,6,7}

b)

No, frozen set is immutable

c)

No, invalid syntax for add method

d)

Yes, now a is {5,6,7}

62.

Set members must not be hashable.

a)

True

b)

False

63.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3])

>>> a

a)

Error, no method called update for set data type

b)

{1, 2, 3, 4, 5}

c)

Error, list can’t be added to set

d)

Error, duplicate item present in list

64.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> a.intersection_update({2,3,4,5})

>>> a

a)

{2,3}

b)

Error, duplicate item present in list

c)

Error, no method called intersection_update for set data type

d)

{1,4,5}

65.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a

>>> b.remove(3)

>>> a

a)

{1,2,3}

b)

Error, copying of sets isn’t allowed

c)

{1,2}

d)

Error, invalid syntax for remove

66.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a.copy()

>>> b.add(4)

>>> a

a)

{1,2,3}

b)

Error, invalid syntax for add

c)

{1,2,3,4}

d)

Error, copying of sets isn’t allowed

67.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a.add(4)

>>> b

a)

0

b)

{1,2,3,4}

c)

{1,2,3}

d)

Nothing is printed

68.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=frozenset([3,4,5])

>>> a-b

a)

{1,2}

b)

Error as difference between a set and frozenset can’t be found out

c)

Error as unsupported operand type for set data type

d)

frozenset({1,2})

69.

What will be the output of the following Python code?

>>> a={5,6,7}

>>> sum(a,5)

a)

5

b)

23

c)

18

d)

Invalid syntax for sum method, too many arguments

70.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> {x*2 for x in a|{4,5}}

a)

{2,4,6}

b)

Error, set comprehensions aren’t allowed

c)

{8, 2, 10, 4, 6}

d)

{8,10}

71.

What will be the output of the following Python code?

>>> a={5,6,7,8}

>>> b={7,8,9,10}

>>> len(a+b)

a)

8

b)

Error, unsupported operand ‘+’ for sets

c)

6

d)

Nothing is displayed

72.

What will be the output of the following Python code?

a={1,2,3}

b={1,2,3}

c=a.issubset(b)

print(c)

a)

True

b)

False

c)

Error, no method called issubset() exists

d)

Syntax error for issubset() method

73.

Is the following Python code valid?

a={1,2,3}

b={1,2,3,4}

c=a.issuperset(b)

print(c)

a)

False

b)

True

74.

What will be the output of the following Python code?

s=set()

type(s)

a)

<’set’>

b)

<class ‘set’>

c)

set

d)

class set

75.

The following Python code results in an error.

s={2, 3, 4, [5, 6]}

a)

True

b)

False

76.

Set makes use of __________

Dictionary makes use of ____________

a)

keys, keys

b)

key values, keys

c)

keys, key values

d)

key values, key values

77.

Which of the following lines of code will result in an error?

a)

s={abs}

b)

s={4, ‘abc’, (1,2)}

c)

s={2, 2.2, 3, ‘xyz’}

d)

s={san}

78.

What will be the output of the following Python code?

s={2, 5, 6, 6, 7}

s

a)

{2, 5, 7}

b)

{2, 5, 6, 7}

c)

{2, 5, 6, 6, 7}

d)

Error

79.

Input order is preserved in sets.

a)

True

b)

False

80.

Write a list comprehension for number and its cube for:

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

a)

[x**3 for x in l]

b)

[x^3 for x in l]

c)

[x**3 in l]

d)

[x^3 in l]

81.

What will be the output of the following Python code?

s={1, 2, 3}

s.update(4)

s

a)

{1, 2, 3, 4}

b)

{1, 2, 4, 3}

c)

{4, 1, 2, 3}

d)

Error

82.

Which of the following functions cannot be used on heterogeneous sets?

a)

pop

b)

remove

c)

update

d)

sum

83.

What will be the output of the following Python code?

s={4>3, 0, 3-3}

all(s)

any(s)

a)

True

False

b)

False

True

c)

True

True

d)

False

False