0% found this document useful (0 votes)
38 views6 pages

Python OOP Exam Questions Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views6 pages

Python OOP Exam Questions Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PacketPrep Exam Paper

Python

1. ____ variable is the variable that is stored inside the function.

A. Local
B. Global

2. Can you use a local variable outside the function?

A. Yes
B. No
C. Only in the special case

3. ____ variables are the variables that can be used in the entire program.

A. Global
B. Local

4. Which keyword is used to assign a local variable?

A. Global
B. Local
C. No, it has no keyword

5. Which keyword is used to assign a global variable?

A. global
B. local
C. No, it has no keyword

6. Can you delete the variable during a program?

A. Yes
B. No

7. By default the numerical data in series is starting from

A. 2

B. 1 C. 0 D. 3
PacketPrep Exam Paper
Python
[Link] of the following is/are advantages of using object oriented
programming

[Link] reusability

[Link] create more than one instance of a class without interference

[Link] independent

[Link] options are correct

9. Which of the following is correct with respect to the OOP concept in Python?

A. Objects are real-world entities while classes are not real.

B. Classes are real-world entities while objects are not real.

C. Both objects and classes are real-world entities.

D. Both objects and classes are not real.

10. How many objects and reference variables are there for the given Python code?
class A:

print(“Inside class”)

A()

A()

obj=A()

A.2and1

B.3and3

C.3and1

D. 3 and 2
PacketPrep Exam Paper
Python

11. Which of the following is False with respect to Python code?

A. “std” is the reference variable for object Student(1,20)

B. id and age are called the parameters.

C. Every class must have a constructor.

D. None of the above

12. What will be the output of below Python code?

A. 1 2 B. 2 1 c. 3 2 d. 4 2
PacketPrep Exam Paper
Python

13. What will be the output of below Python code?

A.100 102 B.102 100 C.101 102

14. Which of the following is correct?

A. id(a1) and id(a2) will have the same.

B> id(a1) and id(a2) will have different

C. Two objects with same value of the attribute cannot be created.

D. None of the above

15. Which of the following is correct?


PacketPrep Exam Paper
Python

A. 5

B. 6

C. 0

D. Error

II. Answer Following All Questions

[Link] a program to print the given pattern

[Link] a program to print the prime numbers between 1 to 100.

[Link] the all types of variables with example programs


PacketPrep Exam Paper
Python
[Link] the all types of methods with example programs

[Link] about self and Constructor

[Link] regarding the polymorphisms, how to achieve it Given


examples

[Link] a program to find the reference variables in the program.

Common questions

Powered by AI

The 'self' keyword in Python is used within class methods to reference instance variables and call other methods on the same object. It allows access to the attributes and methods of the object that is being manipulated. Compared to constructors, which initialize class instances, 'self' is a means of accessing the current object's context within any instance method, ensuring instance-specific operations.

Object-oriented programming in Python enhances code reusability by allowing developers to create classes that encapsulate data and behaviors which can be reused through inheritance and object instantiation. This allows more efficient code management, as changes made in a single class can propagate throughout the program. OOP also allows multiple instances of objects to be created without mutual interference, promoting cleaner and more organized code.

To find reference variables in a Python program, methods such as analyzing the variable assignments, using debugging tools, and employing variable tracking techniques are essential. Employing functions like 'globals()' and 'locals()' can assist in identifying which references exist at different scopes. Identifying reference variables is crucial for understanding code flow, debugging, and optimizing memory usage allocation.

Local variables in Python are defined within a function and are only accessible within that function's scope. They cannot be accessed outside the function where they are defined without an error occurring. This is crucial for encapsulation and preventing unintended side effects that might occur if variables were accessible globally.

The 'global' keyword in Python is beneficial when there is a need to modify or define a variable that can be accessed across different scopes, particularly within functions. It allows global variables to be read and changed inside functions, which is important for maintaining state across a program. However, it should be used cautiously to avoid unintended side effects by preventing functions from unexpectedly altering global states.

Polymorphism in Python allows methods to be defined in a way where they can operate on objects of different classes. This is primarily achieved through method overriding and duck typing, enabling objects to be used interchangeably without modifying their code. This enhances code flexibility and reusability, as the same interface can support different underlying forms or classes of objects.

A class in Python does not necessarily require an explicit constructor if initialization of the object does not require specific operations. The default constructor (__init__) can be omitted if no initialization is needed, making the object creation straightforward. However, this limits the ability to initialize object attributes upon creation. It's important for cases where object-specific starting values are required.

In the provided code snippet, there are three instances of objects created from the class A, as indicated by the calls to A(), and one reference variable (obj) that holds the reference to one of the objects. Therefore, the correct interpretation would be that there are three objects and one reference variable.

Numerical series in Python starting at zero is crucial for indexing, aligning programming logic with zero-based index systems that are standard in most programming languages. This simplifies array and list manipulation, promotes consistency across languages, and prevents off-by-one errors. It's a foundational aspect of loops and collections, where iterations naturally begin from zero.

Deleting variables in Python during runtime can free up memory and resources, allowing for more efficient operations when variables are no longer needed. This can particularly be beneficial in long-running applications to avoid memory leaks. However, improper management could lead to program errors if the deleted variables are referenced later, causing the program to fail or behave unexpectedly. Proper understanding and use are critical to avoid negative implications.

You might also like