WorksheetsPython Quiz BS(N), MSc, BCA
Total questions: 83
Worksheet time: 46mins
__________ keyword is used for creating a function in Python.
define
fun
def
function
What is the output of the given code?
10 20 10
10
20
10 20
What is the output of the given code?
10 20 10 20
10 20 10
10 20 20
Error
Python supports variable number of parameters.
True
False
Function header in Python contains _________________.
function name
list of parameters
return type
all the above
Only A & B
The default return value of any function in Python is _______________.
null
0
None
Garbage value
__________ is the built-in function to know the type of a variable or function.
id()
type()
data_type()
none of the above
___________ are the arguments passed to a function in correct positional order.
Keyword arguments
Default arguments
Variable-length arguments
Required arguments
none of the above
times is ________________ type of argument.
default arguments
keyword arguments
positional arguments
arbitrary positional arguments
arbitrary keyword arguments
Select the advantages of functions
Modular programming
Code re-usability
Improving clarity of the code
All the above
What is the output of Following code?
List = ['spam', 2.0, 5, [10, 20]]
print(List[2])
(a)
What is the output of Following code?
cheeses = ['Cheddar', 'Edam', 'Gouda']
numbers = [42, 123]
print(cheeses, numbers)
['Cheddar', 'Edam', 'Gouda'] [42, 123]
[42, 123] ['Cheddar', 'Edam', 'Gouda']
Compilation Error
No output
What is output of the following Code (Execute in Intrepreter)
cheeses = ['Cheddar', 'Edam', 'Gouda']
'Edam' in cheeses
(a)
In Python, list is mutable
True
False
Which of the following commands will create a list?
list1 = list()
list1 = []
list1 = list([1, 2, 3])
list1 = new List()
What is the output of the following code?
list = [1,2,3,4,5,6,7,8,9,10]
print(list[1:2])
(a)
What is the output of the following code?
list = [1,2,3,4,5,6,7,8,9,10]
print(list[2:1])
(a)
What is the output of the following code?
list = [1,2,3,4,5,6,7,8,9,10]
print(list[::-1])
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[1,2,3,4,5,6,7,8,9,10]
Error
No output
What is the output of the following code?
list = [1,2,3,4,5,6,7,8,9,10]
print(list[::-3])
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Compilation error
[8,9,10]
[10, 7, 4, 1]
What is the output of the following code?
list = []
list.append(1)
list.append(2.0)
list.append("vk")
print(list)
[1, 2.0, 'vk']
Error
['vk', 1, 2.0]
No putput
Tuples in Python are mutable
False
True
How to create a single element tuple
(1,)
(1)
{1}
[1]
tuple([1])
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
What is the output of the code above
(1, '2', 3, 4, 5)
syntax error
(1, 2, 3, 4, 5)
('1', '2', '3', '4', '5')
Which of the following is true
a is assigned a value of 1
b is assigned a value of [2,3]
b is assigned a value of (2,3)
b is assigned a value of 2
What is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
What is the output of the code above ?
1 4
1
1 None
1 [2,3,4]
1 (2,3,4)
What is the output of the program above ?
True
False
The code snippet above outputs
error
None
NaN
-1
What is the output of the code above
None
Syntax Error
-1
Code doesn't compile
The output of the code above is
Key Error
4
Math
The code above prints
Math
Physics
Chemistry
English
4
3.8
3.6
3.7
None
None
None
None
NaN
NaN
NaN
NaN
What is the output of the program above
e
y
t
g
The output of the code above is
[101, 102, 103, 104]
[3.6, 3.7, 3.8, 4]
What is the output of the code above
[3.6, 3.7, 3.8, 4]
[101, 102, 103, 104]
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.
grades[102]
grades.get(102)
grades[2]
grades[3]
grades.key(102)
Which of the following are valid ways to create a dictionary like this
Which of the following code deletes the key 103 and its value
del grades[103]
grades.pop(103)
del grades["103"]
grades.pop("103")
What is the output of the code above
3.9
4
Syntax error
What is the output of the program above
7
6
5
9
4
How to fix the syntax error above ?
grades.pop("Science", None)
grades.pop["Science","None"]
del grades["Math"]
del grades["Math", None]
What is the problem with the code above ?
Dictionary cannot be changed during an iteration
This code will run fine (without syntax errors)
After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.
Which of these about a set is not true?
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
Which of the following is not the correct syntax for creating a set?
set([[1,2],[3,4]])
set([1,2,2,3,4])
set((1,2,3,4))
{1,2,3,4}
What will be the output of the following Python code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
7
Error, invalid syntax for formation of set
4
8
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=" ")
5 5 6
5 6 7
5 5 6 7 7 7
5 6 7 7 7
Which of the following statements is used to create an empty set?
{ }
set()
[ ]
( )
What will be the output of the following Python code?
>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b
{1,2}
True
False
Invalid operation
If a={5,6,7,8}, which of the following statements is false?
print(len(a))
print(min(a))
a.remove(5)
a[2]=45
If a={5,6,7}, what happens when a.add(5) is executed?
a={5,5,6,7}
a={5,6,7}
Error as there is no add function for set data type
Error as 5 already exists in the set
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a+b
{4,5,6,2,8}
{4,5,6,2,8,6}
Error as unsupported operand type for sets
Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
{4,5}
{6}
Error as unsupported operand type for set data type
Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b
{5,6,7,8,10,11}
{7,8}
Error as unsupported operand type of set data type
{5,6,10,11}
What will be the output of the following Python code?
>>> s={5,6}
>>> s*3
Error as unsupported operand type for set data type
{5,6,5,6,5,6}
{5,6}
Error as multiplication creates duplicate elements which isn’t allowed
What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,5,6,8}
>>> a==b
True
False
What will be the output of the following Python code?
>>> a={3,4,5}
>>> b={5,6,7}
>>> a|b
Invalid operation
{3, 4, 5, 6, 7}
{5}
{3,4,6,7}
Is the following Python code valid?
a={3,4,{7,5}}
print(a[2][0])
Yes, 7 is printed
Error, elements of a set can’t be printed
Error, subsets aren’t allowed
Yes, {7,5} is printed
Which of these about a frozenset is not true?
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
What is the syntax of the following Python code?
>>> a=frozenset(set([5,6,7]))
>>> a
{5,6,7}
frozenset({5,6,7})
Error, not possible to convert set into frozenset
Syntax error
Is the following Python code valid?
>>> a=frozenset([5,6,7])
>>> a
>>> a.add(5)
Yes, now a is {5,5,6,7}
No, frozen set is immutable
No, invalid syntax for add method
Yes, now a is {5,6,7}
Set members must not be hashable.
True
False
What will be the output of the following Python code?
>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a
Error, no method called update for set data type
{1, 2, 3, 4, 5}
Error, list can’t be added to set
Error, duplicate item present in list
What will be the output of the following Python code?
>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a
{2,3}
Error, duplicate item present in list
Error, no method called intersection_update for set data type
{1,4,5}
What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a
{1,2,3}
Error, copying of sets isn’t allowed
{1,2}
Error, invalid syntax for remove
What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.copy()
>>> b.add(4)
>>> a
{1,2,3}
Error, invalid syntax for add
{1,2,3,4}
Error, copying of sets isn’t allowed
What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.add(4)
>>> b
0
{1,2,3,4}
{1,2,3}
Nothing is printed
What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=frozenset([3,4,5])
>>> a-b
{1,2}
Error as difference between a set and frozenset can’t be found out
Error as unsupported operand type for set data type
frozenset({1,2})
What will be the output of the following Python code?
>>> a={5,6,7}
>>> sum(a,5)
5
23
18
Invalid syntax for sum method, too many arguments
What will be the output of the following Python code?
>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}
{2,4,6}
Error, set comprehensions aren’t allowed
{8, 2, 10, 4, 6}
{8,10}
What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)
8
Error, unsupported operand ‘+’ for sets
6
Nothing is displayed
What will be the output of the following Python code?
a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)
True
False
Error, no method called issubset() exists
Syntax error for issubset() method
Is the following Python code valid?
a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)
False
True
What will be the output of the following Python code?
s=set()
type(s)
<’set’>
<class ‘set’>
set
class set
The following Python code results in an error.
s={2, 3, 4, [5, 6]}
True
False
Set makes use of __________
Dictionary makes use of ____________
keys, keys
key values, keys
keys, key values
key values, key values
Which of the following lines of code will result in an error?
s={abs}
s={4, ‘abc’, (1,2)}
s={2, 2.2, 3, ‘xyz’}
s={san}
What will be the output of the following Python code?
s={2, 5, 6, 6, 7}
s
{2, 5, 7}
{2, 5, 6, 7}
{2, 5, 6, 6, 7}
Error
Input order is preserved in sets.
True
False
Write a list comprehension for number and its cube for:
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
[x**3 for x in l]
[x^3 for x in l]
[x**3 in l]
[x^3 in l]
What will be the output of the following Python code?
s={1, 2, 3}
s.update(4)
s
{1, 2, 3, 4}
{1, 2, 4, 3}
{4, 1, 2, 3}
Error
Which of the following functions cannot be used on heterogeneous sets?
pop
remove
update
sum
What will be the output of the following Python code?
s={4>3, 0, 3-3}
all(s)
any(s)
True
False
False
True
True
True
False
False
