WorksheetsPython Basics Quiz
Total questions: 12
Worksheet time: 6mins
What is the correct way to print "Hello world" in Python?
print("Hello world")
echo "Hello world"
printf("Hello world")
System.out.println("Hello world")
How do you access the first item in a list called 'bikes'?
bikes[1]
bikes[0]
bikes[-1]
bikes.first()
Which of the following is a correct way to create a dictionary in Python?
dict = {'key': 'value'}
dictionary = ['key', 'value']
map = ('key', 'value')
list = {'key': 'value'}
What is the result of the following list comprehension: squares = [x**2 for x in range(1, 4)]?
[1, 4, 9]
[1, 2, 3]
[1, 8, 27]
[2, 4, 6]
How do you add a new key-value pair to a dictionary in Python?
dict.add('key', 'value')
dict['key'] = 'value'
dict.append('key', 'value')
dict.insert('key', 'value')
What is the correct syntax for an if-else statement in Python?
if (condition) { } else { }
if condition: else:
if condition: else:
if condition: else:
How do you prompt a user for input in Python?
input("Enter your input: ")
scanf("Enter your input: ")
gets("Enter your input: ")
read("Enter your input: ")
What is the purpose of a while loop in programming?
To repeat a block of code a specific number of times
To repeat a block of code as long as a certain condition is true
To execute a block of code only once
To handle exceptions in code
What is a class in programming?
A block of code that repeats
A function that returns a value
A blueprint for creating objects
A method for handling errors
What is the default mode for opening files in Python?
Write mode ('w')
Append mode ('a')
Read mode ('r')
Execute mode ('x')
What is the purpose of the 'try' block in exception handling?
To define a class
To execute code that might cause an error
To repeat a block of code
To open a file
What is the Zen of Python's advice when choosing between a simple and complex solution?
Complex is better than simple
Simple is better than complex
Both are equally good
Avoid both simple and complex solutions
