NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 20
Worksheet time: 15mins
Which of the following is the correct way to print "Hello World" in Python?
print("Hello World")
print("Hello World")
System.out.print("Hello World")
console.log("Hello World")
What is the result of the expression 3 * 4 + 2 ** 3 in Python?
20
24
28
14
Which is the correct way to write a single-line comment in Python?
// This is a comment
/* This is a comment */
# This is a comment
Which comparison operator means "not equal to" in Python?
<>
!=
/=
=!
What is the correct syntax for a while loop in Python?
while (x > 0) { }
while x > 0:
do { } while (x > 0)
while: x > 0
How do you properly define a function with two parameters in Python?
define myFunction(x, y):
def myFunction(x, y):
function myFunction(x, y):
myFunction(x, y) define:
Which method converts a string to lowercase in Python?
toLower()
lowercase()
lower()
to_lower()
Which statement is used to exit a loop prematurely in Python?
exit
break
stop
return
What is the correct way to catch an exception in Python?
catch(Exception e) { }
try-catch(Exception e)
try: except Exception:
on Exception:
How do you access the third character in a string str?
str.charAt(2)
str[2]
str(3)
str.get(2)
What is the result of: "Hello".find("l")?
1
2
3
4
Which operator is used for Finding remainder in Python?
/
//
%
\
How do you check if a substring exists in a string?
contains()
exists()
in
has()
What is the output of: len("Python")?
5
6
7
8
What is the result of: 5 % 2?
0
3
1
2
Which logical operator is used to combine multiple conditions in Python?
and
combine
not
or
What is the result of the expression: True or False and False?
Error
None
False
True
What is a nested control structure in programming?
A control structure that contains another control structure within it
A control structure that does not contain any other control structures
A control structure that is used for input/output operations
A control structure that is used only once
Which of the following is an example of a nested control structure?
An if statement inside a for loop
A function definition
A single if statement
A single for loop
What is the primary benefit of using nested control structures?
They make the code run faster
They allow for more complex decision-making processes
They reduce the number of lines of code
They simplify the debugging process
