Đề thi, bài tập trắc nghiệm online Lập trình Python – Đề 3

0

Bạn đã sẵn sàng chưa? 45 phút làm bài bắt đầu!!!

Bạn đã hết giờ làm bài! Xem kết quả các câu hỏi đã làm nhé!!!


Đề 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

1. What will be the output of `print(bool(0), bool(1), bool(``))`?

A. True True True
B. False True False
C. False False True
D. True False True

2. What is the purpose of a generator in Python?

A. To generate random numbers.
B. To generate documentation for Python code.
C. To create iterators that generate values on-the-fly, saving memory.
D. To manage exceptions in loops.

3. Which of the following data structures is immutable in Python?

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

4. Which of the following is NOT a built-in data type in Python?

A. int
B. float
C. character
D. list

5. In Python, what is the purpose of the `len()` function?

A. To convert a string to lowercase.
B. To calculate the length of a string, list, tuple, or other sequence.
C. To create a new list.
D. To find the maximum value in a sequence.

6. What is the output of `print(`Hello`.replace(`l`, `L`))`?

A. HeLLo
B. Hello
C. HeLlo
D. HellLo

7. What does the `pip` command stand for in Python?

A. Python Input Package
B. Preferred Installer Program
C. Python Index Packages
D. Package Installation for Python

8. What is the role of the `self` parameter in Python class methods?

A. It refers to the class itself.
B. It is a keyword for defining static methods.
C. It refers to the instance of the class.
D. It is used to inherit from parent classes.

9. Which method is used to add an element to the end of a list in Python?

A. insert()
B. append()
C. add()
D. extend()

10. What is the purpose of the `__init__` method in a Python class?

A. To delete an object.
B. To initialize the attributes of an object when it is created.
C. To define the class name.
D. To call a method from a parent class.

11. Which of the following is a built-in function in Python for reading input from the user?

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

12. What is the purpose of the `try...except` block in Python?

A. To define functions.
B. To handle exceptions and errors during program execution.
C. To create loops for iterative tasks.
D. To declare variables.

13. Which of these loop types is NOT available in Python?

A. for loop
B. while loop
C. do-while loop
D. nested loop

14. What is the output of the following Python code?

```python
print(3 > 5 and 10 < 20) ```

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

15. What is the purpose of virtual environments in Python?

A. To improve the speed of Python execution.
B. To manage different Python versions on the same machine.
C. To create isolated environments for Python projects with their own dependencies.
D. To debug Python code.

16. What does the `continue` statement do in a loop in Python?

A. Terminates the loop entirely.
B. Skips the rest of the current iteration and proceeds to the next iteration.
C. Executes the loop body only once.
D. Pauses the loop execution.

17. What is the purpose of list comprehension in Python?

A. To create loops.
B. To define functions.
C. To create lists in a concise way.
D. To handle exceptions in lists.

18. What is the primary purpose of the `if __name__ == `__main__`` block in a Python script?

A. To define the main function of the script.
B. To prevent the script from being executed if imported as a module.
C. To ensure that the script is only run on the main thread.
D. To optimize the script`s execution speed.

19. What is the difference between `==` and `is` operators in Python?

A. `==` checks for value equality, `is` checks for type equality.
B. `==` checks for identity equality, `is` checks for value equality.
C. `==` checks for value equality, `is` checks for identity equality.
D. `==` and `is` are interchangeable and perform the same operation.

20. What is a dictionary in Python?

A. An ordered sequence of items.
B. An unordered collection of key-value pairs.
C. A mutable sequence of numbers.
D. An immutable sequence of characters.

21. Which of the following statements about Python lists is FALSE?

A. Lists are ordered collections of items.
B. Lists can contain elements of different data types.
C. Lists are immutable.
D. Lists are defined using square brackets `[]`.

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. 10
B. 5
C. Error
D. None

23. What is the output of `print(`Python`[1:4])`?

A. Pyth
B. ytho
C. yth
D. Py

24. Which of the following is NOT a valid way to comment in Python?

A. # This is a comment
B. // This is a comment
C. ```This is a multiline comment```
D. ```This is also a multiline comment```

25. What is a module in Python?

A. A keyword for defining functions.
B. A file containing Python definitions and statements.
C. A type of loop structure.
D. A built-in data type.

26. Which of the following is a correct way to open a file named `myfile.txt` in read mode in Python?

A. file = open(`myfile.txt`, `w`)
B. file = open(`myfile.txt`, `r`)
C. file = open(`myfile.txt`, `a`)
D. file = open(`myfile.txt`, `x`)

27. What is a decorator in Python?

A. A way to format strings.
B. A design pattern for creating classes.
C. A function that takes another function and extends or modifies the behavior of the latter function without actually modifying it.
D. A type of loop used for iteration.

28. What is the output of `print(type([1, 2]))` in Python?

A.
B.
C.
D.

29. What is the purpose of the `pass` statement in Python?

A. To indicate a successful operation.
B. To define a function`s return value.
C. It is a null operation; nothing happens when it executes.
D. To raise an exception.

30. What is the difference between function arguments `*args` and `**kwargs` in Python?

A. `*args` for keyword arguments, `**kwargs` for positional arguments.
B. `*args` for arbitrary positional arguments as a tuple, `**kwargs` for arbitrary keyword arguments as a dictionary.
C. `*args` for arbitrary keyword arguments as a list, `**kwargs` for arbitrary positional arguments as a set.
D. `*args` and `**kwargs` are interchangeable and can be used for both positional and keyword arguments.

1 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

1. What will be the output of `print(bool(0), bool(1), bool(''))`?

2 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

2. What is the purpose of a generator in Python?

3 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

3. Which of the following data structures is immutable in Python?

4 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

4. Which of the following is NOT a built-in data type in Python?

5 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

5. In Python, what is the purpose of the `len()` function?

6 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

6. What is the output of `print('Hello'.replace('l', 'L'))`?

7 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

7. What does the `pip` command stand for in Python?

8 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

8. What is the role of the `self` parameter in Python class methods?

9 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

9. Which method is used to add an element to the end of a list in Python?

10 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

10. What is the purpose of the `__init__` method in a Python class?

11 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

11. Which of the following is a built-in function in Python for reading input from the user?

12 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

12. What is the purpose of the `try...except` block in Python?

13 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

13. Which of these loop types is NOT available in Python?

14 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

14. What is the output of the following Python code?

```python
print(3 > 5 and 10 < 20) ```

15 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

15. What is the purpose of virtual environments in Python?

16 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

16. What does the `continue` statement do in a loop in Python?

17 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

17. What is the purpose of list comprehension in Python?

18 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

18. What is the primary purpose of the 'if __name__ == '__main__'' block in a Python script?

19 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

19. What is the difference between `==` and `is` operators in Python?

20 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

20. What is a dictionary in Python?

21 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

21. Which of the following statements about Python lists is FALSE?

22 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

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)
```

23 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

23. What is the output of `print('Python'[1:4])`?

24 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

24. Which of the following is NOT a valid way to comment in Python?

25 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

25. What is a module in Python?

26 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

26. Which of the following is a correct way to open a file named 'myfile.txt' in read mode in Python?

27 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

27. What is a decorator in Python?

28 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

28. What is the output of `print(type([1, 2]))` in Python?

29 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

29. What is the purpose of the `pass` statement in Python?

30 / 30

Category: Đề thi, bài tập trắc nghiệm online Lập trình Python

Tags: Bộ đề 3

30. What is the difference between function arguments `*args` and `**kwargs` in Python?