Font size
WorksheetsPython Programming Quiz
Total questions: 30
Worksheet time: 16mins
What is a correct way to declare a Python variable?
var x = 5
#x = 5
$x = 5
x = 5
True or False: You can declare string variables with single or double quotes.
True
False
True or False: Variable names are not case-sensitive.
True
False
Which is NOT a legal variable name?
my-var
my_var
Myvar
_myvar
What is a correct syntax to add the value 'Hello World', to 3 variables in one statement?
x, y, z = 'Hello World'
x = y = z = 'Hello World'
x|y|z = 'Hello World'
Insert the correct syntax to convert x into a floating point number.
float
int
str
Insert the correct syntax to convert x into an integer.
int
float
str
What does the upper() method do?
Returns the string in upper case
Returns the string in lower case
Removes whitespace from the string
Concatenates two strings
What does the lower() method do?
Returns the string in upper case
Returns the string in lower case
Removes whitespace from the string
Concatenates two strings
What does the strip() method do?
Returns the string in upper case
Returns the string in lower case
Removes whitespace from the beginning or end
Concatenates two strings
How do you concatenate two strings in Python?
Using the + operator
Using the - operator
Using the * operator
Using the / operator
What is the correct way to create an f-string?
txt = f'My name is John, I am {age}'
txt = 'My name is John, I am {age}'
txt = 'My name is John, I am ' + age
txt = f'My name is John, I am age'
What does the bool() function do?
Evaluates any value and returns True or False
Converts a string to an integer
Concatenates two strings
Removes whitespace from a string
What is the output of print(10 > 9)?
True
False
None
Error
What does the if statement do?
Tests a condition and executes code based on the result
Defines a function
Creates a loop
Declares a variable
What is the purpose of the else keyword?
Catches anything not caught by preceding conditions
Tests a condition
Defines a function
Creates a loop
What does the and keyword do?
Combines conditional statements and returns True if both are true
Reverses the result of a condition
Tests a single condition
Creates a loop
What does the or keyword do?
Combines conditional statements and returns True if one is true
Reverses the result of a condition
Tests a single condition
Creates a loop
What is the correct way to define a function in Python?
def myFunction():
function myFunction()
def myFunction:
myFunction() = def
Which of the following is a valid way to create a dictionary?
myDict = []
myDict = ()
myDict = {}
What is the correct way to create a tuple in Python?
myTuple = ()
myTuple = []
myTuple = {}
True or False:
You can declare string variables with single or double quotes.
x = "John"
# is the same as
x = 'John'
True
False
What will be the result of the following code:
print(float(35))
35
35.0
0.35
The file extension for python is _____________________
.py
.bas
.pptx
.xlsx
Which Python command is used to display information on the screen?
Input
Float
String
Study the code snapshot shown and predict the output.
21
40.0
20.0
none
What is Python?
A snake
A coding language
Which of the following is not a valid comparison operator in Python?
==
!=
<=
><
How do you insert COMMENTS in Python code?
#This is a comment
/* This is a comment */
// This is a comment
Which of these collections defines a LIST?
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
("apple", "banana", "cherry")
{"name": "apple", "color": "green"}
