NEW
Font size
WorksheetsPython final questions part 2
Total questions: 62
Worksheet time: 31mins
How do you access the first element of a list my_list = [10, 20, 30]?
my_list[0]
my_list[1]
my_list.first()
my_list[1, 2]
How do you check if a string is empty in Python?
if string == ""
if string.empty()
if string is ""
if len(string) == 0
What will print("Python" == "python") output?
False
True
None
Error
Which of the following will create a list of numbers from 1 to 10 in Python?
range(1, 11)
list(1, 10)
range(1, 10)
list(1 to 10)
Which method is used to remove an item from a dictionary in Python?
pop()
remove()
delete()
discard()
What does the continue statement do in a loop?
Skips to the next iteration.
Exits the loop completely.
Repeats the current iteration.
Stops the program.
Which function is used to determine the type of an object in Python?
type()
typeof()
object_type()
classof()
What will the following code output? print(bool(""))
False
True
None
Error
How do you start a Python script file?
By saving it with a .py extension.
By saving it with a .python extension.
By using #start as the first line.
By running python init in the terminal.
What will print([1, 2, 3] + [4, 5]) output?
[1, 2, 3, 4, 5]
12345
[5, 4, 3, 2, 1]
[1, 2, 3][4, 5]
Which operator is used to repeat a string multiple times in Python?
*
+
&
!
What does the is operator do in Python?
Checks if two variables point to the same object.
Compares the values of two variables.
Assigns a value to a variable.
Tests for membership in a sequence.
Which function is used to round a number in Python?
round()
ceil()
floor()
approx()
How do you create an empty set in Python?
set()
{}
[]
()
What is the output of print(4 // 3)?
1
1.3333
0.75
Error
What will print("Python".find("P")) output?
0
-1
None
Error
What is the correct way to define a dictionary in Python?
{'key': 'value'}
{key = value}
['key', 'value']
(key, value)
Which Python keyword is used to create a generator?
yield
return
generate
create
What does list.pop() do?
Removes and returns the last item in a list.
Adds an item to the end of a list.
Removes an item by index.
Clears the list.
Which keyword is used to check for membership in a sequence?
in
of
has
contains
What is the output of print("PYTHON".lower())?
python
PYTHON
Python
None
Which Python method is used to replace parts of a string?
replace()
change()
update()
switch()
What will print(list(range(5))) output?
[0, 1, 2, 3, 4]
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
[0, 1, 2, 3, 4, 5]
Which method removes all items from a list?
clear()
delete()
remove_all()
empty()
How do you add an item to a set in Python?
add()
insert()
append()
extend()
Which function can convert a list into a set?
set()
convert_set()
make_set()
list_to_set()
What is the purpose of the not keyword in Python?
Reverses the result of a boolean expression.
Compares two values.
Assigns a value to a variable.
Ends a loop.
What is the output of print(type([1, 2, 3]))?
<class 'list'>
<class 'tuple'>
<class 'set'>
<class 'dict'>
Which function can you use to iterate over both keys and values of a dictionary?
items()
keys()
values()
iterate()
What will the following code output? print(10 / 4)
2.5
2
Error
3
Which of the following represents a valid Python module?
A .py file containing Python code.
A .txt file containing text.
A .exe file containing executable code.
A .csv file containing comma-separated values.
How do you handle multiple exceptions in a single try block?
Use multiple except clauses.
Use a try block for each exception.
Write all exceptions on one line separated by semicolons.
Use the finally clause.
Which of the following will check if a string starts with a specific prefix?
startswith()
endswith()
checkprefix()
eginwith()
What will print("5" + "5") output?
55
10
Error
5 + 5
What is the correct way to define a multi-line string in Python?
"""This is a multi-line string"""
// This is a multi-line string //
## This is a multi-line string ##
/** This is a multi-line string */
What does the enumerate() function do in Python?
Returns pairs of indices and elements from a sequence.
Sorts a list.
Reverses a list.
Filters elements in a list.
Which keyword is used to define an anonymous function in Python?
lambda
function
def
anonymous
What is the output of print(4 ** 0.5)?
2.0
2
4
16
Which method is used to get all the keys of a dictionary?
a)
keys()
values()
items()
get_keys()
Which data type is unordered in Python?
set
list
tuple
string
What is the default value of a boolean in Python?
False
None
True
0
What will print(bool(0)) output?
False
True
Error
0
What is the correct way to open a file for writing in Python?
open("file.txt", "w")
open("file.txt", "r")
open("file.txt", "a")
write("file.txt")
Which Python keyword is used to exit a function?
return
break
exit
stop
How do you create a new line in a string in Python?
\n
\t
\\
//
What is the output of print(10 // 3)?
3
3.33
10.0
Error
What will print(type([])) output?
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'set'>
Which function is used to convert a number to a string in Python?
str()
int()
string()
float()
What is the default starting index for Python lists?
0
1
-1
None
How do you remove an element by its index from a list?
pop(index)
remove(index)
delete(index)
discard(index)
What does the max() function do?
Returns the largest item in an iterable.
Returns the total count of elements.
Converts numbers to the largest integer.
Removes the largest value.
Which keyword is used to create a loop that continues as long as a condition is true?
while
for
continue
if
What will print("hello".capitalize()) output?
Hello
HELLO
hello
None
What is the result of print(4 < 2 or 3 > 1)?
True
False
None
Error
What does the split() method do?
Splits a string into a list of substrings.
Reverses the string.
Combines multiple strings into one.
Removes spaces from the string.
How do you check the number of elements in a list?
len(list)
size(list)
count(list)
length(list)
Which of the following is a valid Python variable name?
my_var
2ndVar
my-var
my var
Which Python method converts a list into a string with a delimiter?
join()
split()
combine()
merge()
What is the correct way to get the last element of a list?
my_list[-1]
my_list[0]
my_list[last]
my_list[1:]
What does the startswith() method check in a string?
If the string starts with a specified substring.
If the string is uppercase.
If the string contains whitespace.
If the string is alphanumeric.
What will print("a" in "apple") output?
True
False
Error
None
How do you access the value associated with a key in a dictionary?
dict[key]
dict.getKey()
dict.value(key)
dict(key)
