NEW
Font size
WorksheetsPython Test
Total questions: 25
Worksheet time: 13mins
What is the correct syntax to output "Hello World" in Python?
echo("Hello World");
echo "Hello World"
print("Hello World")
p("Hello World")
How do you insert COMMENTS in Python code?
/*This is a comment*/
#This is a comment
//This is a comment
Which one is NOT a legal variable name?
_myvar
my_var
Myvar
my-var
How do you create a variable with the numeric value 5?
x = int(5)
x = 5
Both answers are correct
What is the correct file extension for Python files?
.pt
.pyth
.pyt
.py
How do you create a variable with the floating number 2.8?
x = float(2.8)
Both answers are correct
x = 2.8
What is the correct syntax to output the type of a variable or object in Python?
print(typeOf(x))
print(typeof x)
print(typeof(x))
print(type(x))
What is the correct way to create a function in Python?
create myFunction():
function myfunction():
def myFunction():
In Python, 'Hello', is the same as "Hello"
True
False
What is the correct syntax to return the first character in a string?
x = "Hello".sub(0, 1)
x = "Hello"[0]
x = sub("Hello", 0, 1)
Which method can be used to remove any whitespace from both the beginning and the end of a string?
len()
ptrim()
Which method can be used to return a string in upper case letters?
upperCase()
uppercase()
toUpperCase()
upper()
Which method can be used to replace parts of a string?
replace()
repl()
replaceString()
switch()
Which operator is used to multiply numbers?
*
x
#
%
Which operator can be used to compare two values?
==
=
<>
><
Which of these collections defines a LIST?
{"apple", "banana", "cherry"}
("apple", "banana", "cherry")
["apple", "banana", "cherry"]
{"name": "apple", "color": "green"}
Which of these collections defines a TUPLE?
{"name": "apple", "color": "green"}
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
("apple", "banana", "cherry")
Which of these collections defines a SET?
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
("apple", "banana", "cherry")
Which of these collections defines a DICTIONARY?
("apple", "banana", "cherry")
{"name": "apple", "color": "green"}
{"apple", "banana", "cherry"}
["apple", "banana", "cherry"]
Which collection is ordered, changeable, and allows duplicate members?
LIST
DICTIONARY
SET
TUPLE
Which collection does not allow duplicate members?
TUPLE
LIST
SET
How do you start writing an if statement in Python?
if x > y then:
if (x > y)
if x > y:
How do you start writing a while loop in Python?
while x > y:
while x > y {
x > y while {
while (x > y)
How do you start writing a for loop in Python?
for x in y:
for each x in y:
for x > y:
Which statement is used to stop a loop?
break
exit
stop
return
