pytho quiz
pytho quiz
a) int x = 10
b) x := 10
c) x = 10
d) var x = 10
2. Which of these data types is immutable in Python?
a) List
b) Set
c) Dictionary
d) Tuple
3. What is the output of the following code?
print(2 ** 3)
a) 6
b) 8
c) 9
d)12
4. Which of these is the correct way to create a function in Python?
a) def my_function{}
b) function my_function():
c) def my_function():
d) function: my_function()
5. How do you declare a comment in Python?
a) // This is a comment
b) # This is a comment
c) <!-- This is a comment -->
d) /* This is a comment */
6. What will the following code output?
def my_function(x, y=2):
return x + y
print(my_function(3))
a) 5
b) 3
c) 2
d) None
a) Default arguments
b) Positional arguments
c) Keyword arguments
d) Arbitrary arguments
8. How can you skip an iteration of a loop in Python?
a) return
b) skip
c) continue
d) pass
a) while True:
c) for True:
d) while False:
Answers
1. Answer:
c) x = 10
In Python, variables are assigned with the = operator.
2. Answer:
d) Tuple
Tuples are immutable, meaning their values cannot be changed after they are created.
3. Answer:
b) 8
2 ** 3 means 2 raised to the power of 3, which equals 8.
4. Answer:
c) def my_function():
This is the correct syntax for defining a function in Python.
5. Answer:
b) # This is a comment
In Python, comments are written using the # symbol.
6. Answer:
a) 5
The function takes one argument 3 and uses the default value y=2, so the result is 3 + 2 =
5.
7. Answer:
b) Positional arguments
Positional arguments are required unless default values are provided.
8. Answer:
c) continue
The continue statement is used to skip the current iteration of the loop and continue with
the next iteration.
9. Answer a) 2 4
The range(2, 6, 2) generates numbers starting from 2 up to (but not including) 6, with a step of 2,
i.e., 2 and 4.
10 Answer
a) while True:
A while True: loop will run infinitely unless a break condition is met.