WorksheetsPython Programming Quiz
Total questions: 30
Worksheet time: 15mins
Which function is used to display output in Python?
display()
printf()
echo()
print()
What symbol is used for single-line comments in Python?
--
/* */
#
//
Which statement is used to exit a loop prematurely?
exit
stop
break
quit
What does the continue statement do in a loop?
Skips the current iteration
Does nothing
Exits the loop
Restarts the loop
What is the correct way to create a string in Python?
str = 'Hello'
str = "Hello"
str = """Hello"""
All of the above
What will "Python"[0] return?
y
P
Python
Error
What does the escape sequence \n represent?
Backspace
Newline
Null
Tab
What is a tuple in Python?
Immutable sequence
Dictionary type
Mutable sequence
Set type
How do you create a tuple with a single element?
t = [1]
t = (1,)
t = {1}
t = (1)
What symbol is used to create a dictionary in Python?
{}
[]
<>
()
What will be the result of: 10 // 3?
4
3
3.33
3.0
What will "Amazing"[1:6:2] return?
"mai"
"mzn"
"maz"
"azn"
What will "hello".capitalize() return?
"Hello"
"HELLO"
"hELLO"
"hello"
What will "Python".replace("Py", "Ja") return?
"Jathon"
"Python"
"Javathon"
Error
How do you access a value in a dictionary?
dict.get(key)
Both A and B
dict[key]
dict->key
What method returns all keys in a dictionary?
keys()
keyList()
allKeys()
getKeys()
What is the difference between remove() and discard() in sets?
remove() raises error if element not found
discard() raises error if element not found
No difference
remove() is faster
Which method reads one line from a file?
getline()
read()
readline()
readlines()
Which exception is raised when dividing by zero?
ArithmeticError
ZeroDivisionError
TypeError
ValueError
What does if name == "main": check?
Function name
If module is run directly
Class name
Variable name
What does the enumerate() function return?
List of indices
List of values
Index-value pairs
Dictionary
What is list comprehension?
List method
List sorting
Elegant way to create lists
List copying
What will [x*2 for x in range(5)] return?
[0, 2, 4, 6, 8]
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]
[0, 1, 2, 3, 4]
What is a virtual environment in Python?
Virtual machine
Isolated Python environment
Testing environment
Cloud environment
What will "-".join(["a","b","c"]) return?
"a-b-c"
"abc"
"['a-b-c']"
Error
What will "{0} and {1}".format("A", "B") return?
"A, B"
"A and B"
"0 and 1"
"A or B"
What does the filter() function return?
Elements where function returns True
Filtered dictionary
Sorted list
All elements
What will "Python"[::-1] return?
"Python"
Error
"Pytho"
"nohtyP"
What will {1, 2, 3}.intersection({2, 3, 4}) return?
Error
{1, 2, 3, 4}
{1, 4}
{2, 3}
What is the DRY principle in programming?
Define Run Yield
Data Retrieval Yearly
Do Review Yearly
Don't Repeat Yourself
