"Think You Know Python? Try These 30 MCQs to Find Out!"
1. What is the correct file extension for Python files?
A. .py
B. .python
C. .pt
D. .pyt
2. Which of the following is a valid variable name in Python?
A. 2variable
B. variable_name
C. variable-name
D. variable name
3. Python supports which programming paradigms?
A. Object-Oriented
B. Procedural
C. Functional
D. All of the above
4. Which of these data types is immutable in Python?
A. List
B. Set
C. Dictionary
D. Tuple
5. Which Python keyword is used to define a function?
A. func
B. define
C. def
D. function
6. What is the output of `print(2 ** 3)` in Python?
A. 8
B. 6
C. 9
D. 16
7. What does the `len()` function return?
A. The last element in a sequence
B. The number of elements in a sequence
C. The length of a string without spaces
D. The number of characters in a string
8. How do you start a comment in Python?
A. //
B. <!-- -->
C. #
D. /* */
9. Which of the following is a mutable data type in Python?
A. String
B. Tuple
C. List
D. Int
10. What will be the output of `print("Hello" + "World")`?
A. HelloWorld
B. Hello World
C. Hello+World
D. Error
11. What is the correct way to declare a dictionary in Python?
A. `{"key": "value"}`
B. `["key": "value"]`
C. `{key=value}`
D. `["key" => "value"]`
12. Which of the following methods adds an element to a list in Python?
A. add()
B. append()
C. push()
D. insert()
13. Which of the following is used to define a block of code in Python?
A. Curly braces
B. Parentheses
C. Indentation
D. Square brackets
14. What will be the output of `print(5 // 2)`?
A. 2.5
B. 2
C. 3
D. 2.0
15. Which of the following is not a built-in data type in Python?
A. List
B. Tuple
C. Class
D. Dictionary
16. How do you convert a string `s = "123"` to an integer in Python?
A. `int(s)`
B. `str(s)`
C. `float(s)`
D. `list(s)`
17. What is the output of the following code?
```
x = [1, 2, 3]
print(x[1:])
```
A. [1, 2]
B. [2, 3]
C. [1, 3]
D. [3]
18. Which of the following is used to import a module in Python?
A. using
B. module
C. include
D. import
19. What is the result of `bool(0)` in Python?
A. True
B. False
C. Error
D. None
20. What is the correct syntax to create a class in Python?
A. `class ClassName:`
B. `def ClassName:`
C. `create ClassName:`
D. `className:`
21. Which of the following is used to handle exceptions in Python?
A. try-except
B. if-else
C. do-catch
D. error handling
22. What does the `is` keyword compare in Python?
A. Values
B. Data types
C. Memory addresses
D. Class types
23. Which of the following operators is used to check if a value exists in a list in Python?
A. in
B. exists
C. includes
D. has
24. What will be the output of the following code?
```
x = "Python"
print(x[-1])
```
A. P
B. n
C. y
D. Error
25. What is the correct way to declare a lambda function in Python?
A. `lambda x: x + 1`
B. `def lambda(x): x + 1`
C. `lambda function(x): x + 1`
D. `lambda_def x: x + 1`
26. What does `continue` do in a Python loop?
A. Exits the loop
B. Skips the rest of the loop and starts a new iteration
C. Jumps to the next loop
D. Stops the program
27. How can you get the number of key-value pairs in a dictionary?
A. `count(dictionary)`
B. `len(dictionary)`
C. `length(dictionary)`
D. `size(dictionary)`
28. How do you remove an element from a set in Python?
A. `remove()`
B. `delete()`
C. `pop()`
D. `discard()`
29. Which of the following is the correct way to open a file in Python?
A. `file.open("filename.txt")`
B. `open("filename.txt")`
C. `file("filename.txt", "r")`
D. `open_file("filename.txt")`
30. What will the following code output?
```
a = [1, 2, 3, 4, 5]
print(a[0:3])
```
A. [1, 2, 3]
B. [2, 3, 4]
C. [1, 2, 3, 4]
D. [0, 1, 2]
Here are the answers to the 30 Python MCQs
A. .py
B. variable_name
D. All of the above
D. Tuple
C. def
A. 8
B. The number of elements in a sequence
C. #
C. List
A. HelloWorld
A. {"key": "value"}
B. append()
C. Indentation
B. 2
C. Class
A. int(s)
B. [2, 3]
D. import
B. False
A. class ClassName:
A. try-except
C. Memory addresses
A. in
B. n
A. lambda x: x + 1
B. Skips the rest of the loop and starts a new iteration
B. len(dictionary)
D. discard()
B. open("filename.txt")
A. [1, 2, 3]

Comments
Post a Comment