0% found this document useful (0 votes)
2 views

Basic_Programming_Concepts_Test

The document contains a test on basic programming concepts in Python, consisting of multiple-choice questions and a matching section. Key topics include inheritance, encapsulation, decorators, generators, iterators, and context managers. Each question assesses understanding of fundamental programming principles and Python syntax.

Uploaded by

Maria Ch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic_Programming_Concepts_Test

The document contains a test on basic programming concepts in Python, consisting of multiple-choice questions and a matching section. Key topics include inheritance, encapsulation, decorators, generators, iterators, and context managers. Each question assesses understanding of fundamental programming principles and Python syntax.

Uploaded by

Maria Ch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Basic Programming Concepts Test

Question 1: Multiple Choice Questions (20 Marks)


1. 1. What is inheritance in Python?

 A. Reusing code from another class


 B. Encrypting data
 C. Creating functions
 D. Repeating a loop

2. 2. What keyword is used to create a subclass in Python?

 A. extend
 B. class
 C. inherits
 D. derive

3. 3. Which of the following best defines encapsulation?

 A. Hiding the implementation details


 B. Inheriting properties
 C. Looping through values
 D. Using regular expressions

4. 4. What symbol is used to access a private attribute (by convention)?

 A. @
 B. #
 C. __ (double underscore)
 D. //

5. 5. Which of these is a regular expression pattern to match a digit?

 A. \d
 B. \D
 C. .
 D. \s

6. 6. Which module provides regex support in Python?

 A. regpy
 B. re
 C. pyregex
 D. pattern
7. 7. What is a destructor in Python?

 A. A function that creates an object


 B. A function that deletes a file
 C. __del__ method
 D. A decorator

8. 8. When is the destructor called?

 A. When an object is created


 B. When a class is defined
 C. When the object is deleted or goes out of scope
 D. When you import a module

9. 9. What symbol is used for decorators in Python?

 A. #
 B. *
 C. @
 D. $

10. 10. Which of these is a valid decorator use?

 A. @staticmethod
 B. #decorator
 C. !wraps
 D. *override

11. 11. What does a generator return?

 A. A list
 B. A value and stops forever
 C. An iterator using yield
 D. A string

12. 12. What keyword is used to create a generator?

 A. return
 B. pass
 C. yield
 D. def

13. 13. What is the purpose of an iterator?

 A. To sort data
 B. To loop over data using __next__()
 C. To check errors
 D. To reverse a list
14. 14. Which method is required in an iterator class?

 A. __sum__()
 B. __add__()
 C. __iter__() and __next__()
 D. __start__()

15. 15. What does a context manager help manage?

 A. Loops
 B. Imports
 C. Resources like files using with
 D. Memory addresses

16. 16. What keyword is used with context managers?

 A. for
 B. with
 C. open
 D. def

17. 17. Which method is used to initialize a class?

 A. __start__()
 B. __init__()
 C. __create__()
 D. __begin__()

18. 18. What does re.search() do?

 A. Finds all matches


 B. Returns a list
 C. Returns the first match
 D. Deletes the text

19. 19. What does yield do in a function?

 A. Exits the function


 B. Returns multiple values and pauses
 C. Sorts a list
 D. Creates a decorator

20. 20. What happens when an iterator is exhausted?

 A. It throws a StopIteration error


 B. It resets
 C. It returns empty string
 D. It loops again
Question 2: Match the Column (8 Marks)
Match Column A with the correct description in Column B:

Column A Column B
1. Inheritance E. Reuses features from another class
2. Encapsulation B. Hides internal details of an object
3. Regex D. Searches strings using patterns
4. Destructor F. Cleans up when object is deleted
5. Decorator C. @ symbol used to modify functions
6. Generator G. Returns values using yield
7. Iterator H. Has __iter__() and __next__() methods
8. Context Manager A. Helps manage resources like files

You might also like