NEW
Font size
WorksheetsNRIT_Python_Quiz02
Total questions: 50
Worksheet time: 25mins
What is the output of print([1, 2, 3] + [4, 5, 6])?
[1, 2, 3, 4, 5, 6]
[5, 7, 9]
[4, 5, 6, 1, 2, 3]
Error
What does list1.append(5) do?
Adds 5 to the end of list1
Inserts 5 at index 0
Deletes index 5
Raises an error
What is the output of print(len([1, [2, 3], 4]))?
3
4
5
2
How do you remove an element from a list by value?
list.remove(value)
list.delete(value)
list.pop(value)
del list[value]
What is the result of list1 = [1, 2, 3] and list1 * 2?
[1, 2, 3, 1, 2, 3]
[1, 2, 3, 2]
[1, 2, 3, 1]
[2, 4, 6]
What is the output of dict1 = {'a':1, 'b':2}; print(dict1['a'])?
'a'
1
2
Error
How can you get all the keys of a dictionary?
dict.keys()
dict.values()
dict.items()
dict.get()
Which method removes a key-value pair from a dictionary?
del dict[key]
dict.pop(key)
dict.remove(key)
Both a and b
What happens when you try to access a key that doesn't exist in a dictionary?
Returns None
Raises KeyError
Prints 0
Creates the key
What is the output of len({'a': 1, 'b': 2, 'c': 3})?
3
6
2
1
What is a key property of a Python set?
Allows duplicate values
Maintains insertion order
Elements are unique
Can store lists
What is the result of {1, 2, 3} & {3, 4, 5}?
{1, 2, 3, 4, 5}
{3}
{}
{1, 2, 4, 5}
What does set1.add(5) do?
Adds 5 to set1
Inserts 5 at index 0
Removes 5 from set1
Raises an error
What does set1.update([4, 5, 6]) do?
Replaces elements
Adds multiple elements
Deletes elements
Returns an error
Which set operation removes elements?
set.remove(value)
set.discard(value)
set.pop()
All of the above
Which of these is a keyword in Python?
input
class
add
Which identifier is valid in Python?
my_var
2var
my-var
if
How do you check reserved keywords?
help("keywords")
import keyword; keyword.kwlist
keywords()
keyword.list()
Are Python identifiers case-sensitive?
Yes
No
What will print(10 if True else 20) output?
10
20
None
Error
What is the output of if 5 > 2: print("Yes")?
Yes
Error
Nothing
5
What will be the output of the following code? if 10 < 20: if 5 < 10: print("Nested If Works")
No output
Nested If Works
Error
10 < 20 is True
What does an if-elif-else block do?
Executes all conditions
Executes only one true condition
Runs if all conditions are false
Only works with loops
What will be printed? x = 10 if x > 5: print("Greater") elif x < 5: print("Smaller") else: print("Equal")
Greater
Smaller
Equal
Error
What will be the output? if 0: print("Yes") else: print("No")
Yes
No
Error
None
Which statement is true about if-elif-else?
It must have an else
elif is mandatory
It can have multiple elif conditions
if must be at the end
How many times does this loop execute? for i in range(5): print(i)
4
5
Infinite
6
What will happen? count = 0 while count < 3: print(count) count += 1
Prints 0 1 2
Prints 0 1 2 3
Infinite loop
Error
What does range(1, 10, 2) produce?
[1, 3, 5, 7, 9]
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]
[1, 10]
Which loop runs at least once?
for
while
do-while
Python does not have do-while
What is the output? for i in "Python": print(i, end=" ")
P y t h o n
Python
Error
Pyt hon
What does break do?
Exits the entire loop
Skips the next iteration
Stops the program
Continues to the next iteration
What is the output? for i in range(5): if i == 3: break print(i)
0 1 2
0 1 2 3 4
3 4
0 1 2 3
What does continue do in a loop?
Exits the loop
Skips the current iteration
Stops execution
Repeats the last iteration
What is the output?
for i in range(5): if i == 2:
continue
print(i)
0 1 3 4
0 1 2 3 4
2 3 4
0 1
Can break be used inside a function?
Yes
No
What is the output? def add(x, y): return x + y print(add(2, 3))
5
2 3
None
Error
How do you define a function?
define func():
def func():
function func():
void func():
What will happen if a function has no return statement?
Returns None
Returns 0
Returns an error
Returns empty string
What is the correct syntax for a function with a default argument?
def func(a=10):
def func(a: 10):
def func(a == 10):
def func(10=a):
What is the output? def multiply(a, b=2): return a * b print(multiply(3))
3
6
Error
None
What is the type of type({})?
dict
class
tuple
list
What does pass do in Python?
Skips execution
Exits loop
Stops function execution
Runs return 0
What is the correct syntax to get the first element of a tuple?
tuple[0]
tuple.get(0)
tuple.first()
tuple[1]
Which keyword is used to create an empty set?
set()
{}
emptyset()
list()
What does is do?
Checks identity
Checks equality
Assigns values
Creates a variable
What will be the output? x = [5, 6, 7] y = [6, 7, 8] print(x - y)
Error
{6, 7}
{5, 8}
{5}
What will be printed? print(type([]) is list)
True
False
Error
None
What is the output? print("Python"[::-1])
nohtyP
Python
Error
nPhtyo
What is the result of 10 == 10.0?
True
False
Error
None
