Đề thi, bài tập trắc nghiệm online Lập trình PythonĐề 3 – Bài tập, đề thi trắc nghiệm online Lập trình Python Đăng vào 2 Tháng 5, 2026 bởi admin Đề 3 – Bài tập, đề thi trắc nghiệm online Lập trình Python Đề 3 – Bài tập, đề thi trắc nghiệm online Lập trình Python Số câu30Quiz ID11578 Làm bài Câu 1 1. What will be the output of `print(bool(0), bool(1), bool(''))`? A A. True True True B B. False True False C C. False False True D D. True False True Câu 2 2. What is the purpose of a generator in Python? A A. To generate random numbers. B B. To generate documentation for Python code. C C. To create iterators that generate values on-the-fly, saving memory. D D. To manage exceptions in loops. Câu 3 3. Which of the following data structures is immutable in Python? A A. List B B. Dictionary C C. Tuple D D. Set Câu 4 4. Which of the following is NOT a built-in data type in Python? A A. int B B. float C C. character D D. list Câu 5 5. In Python, what is the purpose of the `len()` function? A A. To convert a string to lowercase. B B. To calculate the length of a string, list, tuple, or other sequence. C C. To create a new list. D D. To find the maximum value in a sequence. Câu 6 6. What is the output of `print('Hello'.replace('l', 'L'))`? A A. HeLLo B B. Hello C C. HeLlo D D. HellLo Câu 7 7. What does the `pip` command stand for in Python? A A. Python Input Package B B. Preferred Installer Program C C. Python Index Packages D D. Package Installation for Python Câu 8 8. What is the role of the `self` parameter in Python class methods? A A. It refers to the class itself. B B. It is a keyword for defining static methods. C C. It refers to the instance of the class. D D. It is used to inherit from parent classes. Câu 9 9. Which method is used to add an element to the end of a list in Python? A A. insert() B B. append() C C. add() D D. extend() Câu 10 10. What is the purpose of the `__init__` method in a Python class? A A. To delete an object. B B. To initialize the attributes of an object when it is created. C C. To define the class name. D D. To call a method from a parent class. Câu 11 11. Which of the following is a built-in function in Python for reading input from the user? A A. print() B B. input() C C. read() D D. scan() Câu 12 12. What is the purpose of the `try...except` block in Python? A A. To define functions. B B. To handle exceptions and errors during program execution. C C. To create loops for iterative tasks. D D. To declare variables. Câu 13 13. Which of these loop types is NOT available in Python? A A. for loop B B. while loop C C. do-while loop D D. nested loop Câu 14 14. What is the output of the following Python code? ```python print(3 > 5 and 10 < 20) ``` A A. True B B. False C C. Error D D. None Câu 15 15. What is the purpose of virtual environments in Python? A A. To improve the speed of Python execution. B B. To manage different Python versions on the same machine. C C. To create isolated environments for Python projects with their own dependencies. D D. To debug Python code. Câu 16 16. What does the `continue` statement do in a loop in Python? A A. Terminates the loop entirely. B B. Skips the rest of the current iteration and proceeds to the next iteration. C C. Executes the loop body only once. D D. Pauses the loop execution. Câu 17 17. What is the purpose of list comprehension in Python? A A. To create loops. B B. To define functions. C C. To create lists in a concise way. D D. To handle exceptions in lists. Câu 18 18. What is the primary purpose of the 'if __name__ == '__main__'' block in a Python script? A A. To define the main function of the script. B B. To prevent the script from being executed if imported as a module. C C. To ensure that the script is only run on the main thread. D D. To optimize the script's execution speed. Câu 19 19. What is the difference between `==` and `is` operators in Python? A A. `==` checks for value equality, `is` checks for type equality. B B. `==` checks for identity equality, `is` checks for value equality. C C. `==` checks for value equality, `is` checks for identity equality. D D. `==` and `is` are interchangeable and perform the same operation. Câu 20 20. What is a dictionary in Python? A A. An ordered sequence of items. B B. An unordered collection of key-value pairs. C C. A mutable sequence of numbers. D D. An immutable sequence of characters. Câu 21 21. Which of the following statements about Python lists is FALSE? A A. Lists are ordered collections of items. B B. Lists can contain elements of different data types. C C. Lists are immutable. D D. Lists are defined using square brackets `[]`. Câu 22 22. What will be the output of the following Python code snippet? ```python x = 5 def modify_x(val): x = val modify_x(10) print(x) ``` A A. 10 B B. 5 C C. Error D D. None Câu 23 23. What is the output of `print('Python'[1:4])`? A A. Pyth B B. ytho C C. yth D D. Py Câu 24 24. Which of the following is NOT a valid way to comment in Python? A A. # This is a comment B B. // This is a comment C C. '''This is a multiline comment''' D D. '''This is also a multiline comment''' Câu 25 25. What is a module in Python? A A. A keyword for defining functions. B B. A file containing Python definitions and statements. C C. A type of loop structure. D D. A built-in data type. Câu 26 26. Which of the following is a correct way to open a file named 'myfile.txt' in read mode in Python? A A. file = open('myfile.txt', 'w') B B. file = open('myfile.txt', 'r') C C. file = open('myfile.txt', 'a') D D. file = open('myfile.txt', 'x') Câu 27 27. What is a decorator in Python? A A. A way to format strings. B B. A design pattern for creating classes. C C. A function that takes another function and extends or modifies the behavior of the latter function without actually modifying it. D D. A type of loop used for iteration. Câu 28 28. What is the output of `print(type([1, 2]))` in Python? A A. B B. C C. D D. Câu 29 29. What is the purpose of the `pass` statement in Python? A A. To indicate a successful operation. B B. To define a function's return value. C C. It is a null operation; nothing happens when it executes. D D. To raise an exception. Câu 30 30. What is the difference between function arguments `*args` and `**kwargs` in Python? A A. `*args` for keyword arguments, `**kwargs` for positional arguments. B B. `*args` for arbitrary positional arguments as a tuple, `**kwargs` for arbitrary keyword arguments as a dictionary. C C. `*args` for arbitrary keyword arguments as a list, `**kwargs` for arbitrary positional arguments as a set. D D. `*args` and `**kwargs` are interchangeable and can be used for both positional and keyword arguments. Đề 2 – Bài tập, đề thi trắc nghiệm online Sinh lý hô hấp Đề 4 – Bài tập, đề thi trắc nghiệm online Cơ sở sinh thái học