Worksheetspython part2(36-70)
Total questions: 34
Worksheet time: 17mins
How do you write a single-line comment in Python?
# comment
// comment
/* comment */
comment
What is the result of 10 % 3 in Python?
1
3
30
0
How do you handle exceptions in Python?
try-except
catch-throw
catch-finally
throw-except
Which of the following is the correct way to define a class in Python?
class MyClass:
define MyClass:
MyClass class:
object MyClass:
Which statement is used to exit a loop in Python?
break
exit
end
return
Which method is used to add an element to the end of a list?
append()
add()
insert()
extend()
What does len() function do in Python?
Returns the length of a string or list.
Converts a string to lowercase.
Adds two strings together.
Returns the number of items in a tuple.
Which of the following is the correct way to create a tuple?
my_tuple = (1, 2, 3)
my_tuple = [1, 2, 3]
my_tuple = {1, 2, 3}
my_tuple = 1, 2, 3
What is the correct way to check if a value is in a list in Python?
if x in list:
if list.contains(x):
if x in list[]:
if list.includes(x):
What does the range() function do in Python?
Generates a list of numbers.
Returns a string from a list.
Reverses a list.
Adds two numbers together.
What is the result of the following code: print("abc" + "def")?
abcdef
abc def
ab cdef
None
Which Python method is used to find the index of an element in a list?
index()
position()
find()
locate()
How do you make a string lowercase in Python?
lower()
to_lower()
downcase()
case_lower()
Which of the following Python functions converts a string to a number?
int()
float()
str()
number()
Which keyword is used to define a function in Python?
def
function
func
define
What will print(2 + 3 * 4) output?
14
20
18
12
What is the output of print(2 == 2)?
True
False
None
Error
Which of the following is used to define a dictionary in Python?
{}
[]
()
<>
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
