WorksheetsPython basics
Total questions: 15
Worksheet time: 8mins
Which function is used to display output on the console in Python?
input()
print()
display()
output()
How do you get user input in Python?
get()
input()
user_input()
read()
Which operator is used to assign a value to a variable in Python?
==
<=
=
-=
What is the result of the following expression: 5 + 3 * 2?
10
11
16
13
Which operator is used for exponentiation in Python?
^
//
%
**
Which logical operator is used to perform a logical AND operation in Python?
&
&&
|
and
What will be the output of the following expression: 10 > 5 and 3 < 2?
True
False
Error
None
How do you convert a variable to an integer in Python?
to_int()
cast_int()
int()
convert_int()
Which conditional statement is used to execute a block of code when a condition is true?
for
while
if
else
What is the syntax for a for loop in Python?
for i in range(start, end):
for i in range(end):
for i in range(start, end, step):
for i in range(end, start, -step):
How do you exit a loop prematurely in Python?
exit()
break()
continue()
stop()
What is the output of the following code snippet
x = 10
while x > 0:
print(x)
x -= 1
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
10
None
Which of the following is NOT a valid casting function in Python?
int()
cast()
float()
str()
What will be the output of the following code snippet?
x = 5
if x > 2 and x < 10:
print("Valid")
else:
print("Invalid")
valid
error
invalid
None
Which operator is used to concatenate two strings in Python?
*
-
&
+
