NEW
Font size
WorksheetsProgramming
Total questions: 25
Worksheet time: 13mins
What is an iterator in Python?
A container that can hold multiple values
An object that can be iterated upon
A variable that holds a single value
A function that takes an iterable as input
Which of the following is an example of an iterable in Python?
List
Integer
String
All of the mention
What is the purpose of the 'print()' function in Python?
To read user input from the keyboard.
To write text to the console.
To format strings using placeholders.
To perform mathematical calculations.
Which of the following will produce an error when used as an argument to the 'print()' function?
5
"Hello"
[1, 2, 3]
{"key": "value"}
What is the syntax for printing a variable 'x' using the 'print()' function?
print x
print(x)
print("x")
print"x"
How do you include a newline character in a 'print()' statement?
Use the '\n' escape sequence.
Use the ';' character.
Use the '+' operator.
Use the '*' operator.
What does the 'print()' function do in Python?
Display the contents of a file on the screen
Print a message to the console
Return the value of an expression
Open a new command prompt
Which of the following is a valid way to print the string "Hello, World!" using the 'print()' function?
print "Hello, World!"
print ("Hello, World!")
Print ("Hello, World!")
PRINT "Hello, World!"
What is the output of the following code?
x = 3 and y = 5
x = 3, y = 5
x = 3; y = 5
x, y = 3, 5
What is the output of the following code?
5
"5"
x+y
Error
Which of the following is a valid way to print the values of multiple variables using the 'print()' function?
print(x, y, z)
print(x; y; z)
print(x + y + z)
print(x y z)
What is the output of the following code: print("apple", "banana", "orange", sep=", ")
"apple banana orange"
"apple, banana, orange"
"apple,banana,orange"
"apple , banana , orange"
What is the purpose of the 'sep' parameter in the 'print()' function?
It specifies the character to use between separate print arguments
It specifies the number of spaces between separate print arguments
It specifies the color of the text to be printed
It specifies the type of file to be printed to
What is the purpose of the 'end' parameter in the print() function?
It specifies the character to use between separate print arguments
It specifies the number of spaces between separate print arguments
It specifies the color of the text to be printed
It specifies the character to print at the end of the output
What is the correct syntax for creating an empty list in Python?
[]
[0]
()
{}
Which of the following is NOT a valid method to add an element to a list in Python?
append()
insert()
add()
extend()
Which of the following is the correct way to access the first element of a list in Python?
list[1]
list[0]
list.first()
list.pop()
What is the result of the following code:
numbers = [1, 2, 3, 4]
print(numbers[1:3])
[1, 2]
[2, 3]
[2, 3, 4]
[1, 2, 3]
What is the result of the following code:
name = input("What is your name? ")
print("Hello, " + name + "!")
The code will not run because it contains a syntax error
The code will run, but no output will be produced
The code will run and output the string "Hello, World!"
The code will run and output the string "Hello, " followed by the user's name input
What is the output of the following code snippet?
[1, 5, 3, 4]
[5, 2, 3, 4]
[1, 5, 3]
[1, 5, 3, 5]
What is the output of the following code snippet?
[1, 2, 3, 4]
[1, 3, 4]
[2, 3, 4]
[1, 2, 4]
What is the output of the following code snippet?
[2, 4, 6]
[1, 2, 3, 1, 2, 3]
[1, 2, 3, 2, 4, 6]
[1, 4, 9]
How to comment a single line in python?
!
#
'''
()
How to comment multiple line in python?
''' '''
{ }
[ ]
# #
What will be the output of the following code?
x = Input ("Please do not continue, enter the number to cycle")
print (x)
number enter by user
NameError
Please do not continue
x
