Python MCQ Test (25 Marks)

Python Basics Quiz

Python Basics Quiz

1. Which of the following is a valid variable name in Python?

A. 1variable
B. variable_name
C. variable-name
D. variable.name

2. What is the output of: print(2 ** 3)?

A. 6
B. 8
C. 9
D. Error

3. What is the correct way to create a list in Python?

A. list = {1, 2, 3}
B. list = [1, 2, 3]
C. list = (1, 2, 3)
D. list = "1, 2, 3"

4. Which of the following data types is immutable in Python?

A. List
B. Dictionary
C. Tuple
D. Set

5. What is the output of: print(len("Hello"))?

A. 4
B. 5
C. 6
D. Error

6. What is the keyword used to define a function in Python?

A. func
B. define
C. def
D. function

7. Which of the following is used to include a module in Python?

A. include
B. import
C. module
D. package

8. What is the correct way to declare a dictionary in Python?

A. dict = {\"key\": \"value\"}
B. dict = [\"key\": \"value\"]
C. dict = (\"key\": \"value\")
D. dict = \"key=value\"

9. What will be the output of: print(type(10))?

A.
B.
C.
D.

10. How do you write a comment in Python?

A. // This is a comment
B.
C. # This is a comment
D. \\ This is a comment

11. Which of these is not a core data type in Python?

A. List
B. Tuple
C. Class
D. Dictionary

12. What will be the output of: print(10 // 3)?

A. 3
B. 3.33
C. 4
D. Error

13. What is the file extension for Python scripts?

A. .py
B. .python
C. .script
D. .code

14. Which function is used to read input from the user?

A. read()
B. input()
C. scan()
D. readline()

15. What is the correct way to create an infinite loop in Python?

A. while True:
B. while(1)
C. while(false):
D. for(;;)

16. What is the output of: print(3 * 'Hello')?

A. HelloHelloHello
B. Error
C. 3Hello
D. None

17. Which of the following is used to create a new line in a string?

A. \\n
B. \\t
C. \\r
D. \\b

18. How do you write an empty function in Python?

A. def func() {}
B. def func(): pass
C. def func() -> None
D. def func(): null

19. Which of the following is a valid way to handle exceptions in Python?

A. try-catch
B. try-except
C. catch-try
D. handle-exception

20. What will be the output of: print(5 == 5.0)?

A. True
B. False
C. Error
D. None

21. Which method is used to remove whitespace from the beginning and end of a string?

A. strip()
B. trim()
C. clean()
D. remove()

22. What does the len() function do in Python?

A. Counts the number of elements in a list
B. Returns the length of a string
C. Works with both strings and lists
D. All of the above

23. What is the output of: print(10 % 3)?

A. 1
B. 0.333
C. 3
D. Error

24. How can you convert a string to an integer in Python?

A. str()
B. int()
C. float()
D. cast()

25. What is the correct syntax to check if a key exists in a dictionary?

A. if key in dict:
B. if dict.key:
C. if key exists dict:
D. if key of dict:

Comments

Popular posts from this blog

Programming Notes by Atul Kalukhe