WorksheetsProgrammingwithPython(MockTestObjectives)
Total questions: 55
Worksheet time: 18mins
What is the data type of the result of the expression 10 / 5?
int
float
complex
string
What is the output of the expression 5 + 3 * 2?
16
11
10
13
Which operator is used for floor division ?
/
//
%
**
What will be the output of type(None)?
<class 'Nonetype'>
<class 'None'>
<class 'null'>
<class 'object'>
What is the value of the expression 2**3**2?
64
512
36
81
What does the logical operator ( not ) do in Python?
Returns the opposite boolean value.
Returns the value if it's not zero.
Converts the value to a string.
Checks for inequality.
What is the result of the comparison 5 < 10 and 20 > 15 ?
5
False
True
None
Which of the following is a valid Python variable name?
9variable
my-variable
_myVariable
for
Which Python keyword is used to define a function?
func
function
def
define
Which statement is used to do nothing, serving as a placeholder?
none
return
pass
continue
Which two operators in Python can be chained together for comparison, e.g., a < b < c ?
Arithmetic
Bitwise
Assignment
Comparision
What is the output of the following loop?
0 2
0 1
0 2 4
1 2
How many times will the following code print "Hello"?
5
0
1
Infinite
Which statement is used to terminate the entire loop immediately?
pass
continue
stop
break
If an if condition is False, which block of code is executed next if it exists?
else if
finally
except
elif or else
In a Python for loop, what does the in keyword typically iterate over?
A function
An integer
An iterable
A keyword
What is the output of the following code?
python
pyt
p y t h
p y t o n
What is the index of the character 'o' in the string "Hello World"?
3
4
7
0
What is the length of the string "Python\n" (where \n is a newline character)?
6
7
8
5
What is the result of the string slice "Hello"[1:4] ?
"ell"
"ello"
"hel"
"HI"
Which string method converts all characters in a string to uppercase?
capitalize()
title()
upper()
casefold()
The operation 'Py' * 3 results in:
'PyPyPy'
'3Py'
'Py + Py + Py'
Error
What will be the output of 'abc'.startswith('a')?
True
False
'a'
0
Which of the following is NOT a method that can be used on a string?
strip()
count()
append()
replace()
Which method is used to remove a specific item by value from a list?
pop()
delete()
remove()
discard()
Given my_list = [10, 20, 30], what is the result of my_list[1] = 25?
Error, lists are immutable.
[10, 20, 30]
[10, 25, 30]
[25, 20, 30]
Which built-in function returns the number of items in a list or tuple?
size()
count()
len()
length()
What is the key difference between a list and a tuple in Python?
Lists can hold multiple types, tuples cannot.
Lists are mutable, tuples are immutable.
Tuples are always shorter than lists.
Lists use parentheses () and tuples use square brackets [].
Which method is used to add all the elements of an iterable (like another list) to the end of a list?
append()
insert()
merge()
extend()
What will be the output of (1, 2, 3) + (4, 5)?
(1, 2, 3, 4, 5)
(5, 7, 3)
Error
[1, 2, 3, 4, 5]
In a Python dictionary, what are the elements stored as?
Values only
Indexed positions
Key-Value points
Ordered sequences
Which method is the safer way to access a dictionary value, as it returns a default value instead of raising a KeyError if the key is not found?
dict['key']
dict.get('key')
dict.find('key')
dict.lookup('key')
What characteristic of a set's elements ensures that each element is unique?
They must be mutable.
They must be indexed.
They must be hashable.
They must be integers.
Which operation is used to find the common elements between two sets?
Union (|)
Difference (-)
Intersection (&)
Concatenation (+)
What is the output of len({ 'a' : 1, 'b' : 2, 'c' : 3}) ?
6
3
0
Error
What is the term for a function that does not explicitly use a return statement?
Void function
Generator function
Non-fruitful function
Lambda function
What are the variables defined inside a function called?
Global variables
Local variables
Function variables
Module variables
Which keyword is used within a function to assign a value to a variable defined outside of the function's local scope?
this
outer
global
var
What is the default mode when opening a file using the open() function if no mode is specified?
Write (w)
Read (r)
Append (a)
Read and write (r+)
When should the with open(...) construct be used for file handling?
Only for reading binary files.
To automatically close the file, even if errors occur.
To prevent users from writing to the file.
It is only required for network file access.
What is the output of the following code?
0 1 2 3 4
0 1 2 3
1 2 3 4
Error
What is the final value of my_list after running the following code?
[1, 2, 3, 4, 5]
[1, 2, 8]
[1, 2, [3, 4], 5]
[1, 2, 3, 4]
What is the output of the following code?
gram
ogrm
ramm
gramm
How many times is the asterisk (*) printed by the following code?
2
3
5
6
What is the output of the following code?
3
4
3.333
1
What is the value of result after the following code runs?
'P'
'h'
Error
4
What is the output of the following loop?
30 40
10 20
10 20 30 40
10 20 40
What is the output of the following code?
0
10
None
KeyError
What will happen when you run the following code?
(1, 5, 3)
(1, 2, 3, 5)
A TypeError is raised.
(1, 5, 3) is printed, but a warning is issued.
What is the output of the following code?
True
False
Error
0
What is the output of the following code?
15
510
'510'
Error
What is the final value of numbers?
[1, 9, 9, 5]
[1, 9, 9, 4, 5]
[1, 9, 5]
[1, 9, 9]
What is the output of the following code?
5 End
End
5
Nothing is printed
What is the output of the following code?
Alice Hello
Hello Alice
Error: message not provided
Hello
What is the final value of result?
{1, 2, 3, 4, 5}
{3}
{1, 2, 4, 5}
{1, 2, 3}, {3, 4, 5}
