Files
python-bootcamp/Scott_Submissions/Reading_Material_Notes.rtf
T
2023-06-14 15:54:55 -07:00

120 lines
11 KiB
Plaintext

{\rtf1\ansi\ansicpg1252\cocoartf2580
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 LucidaGrande;}
{\colortbl;\red255\green255\blue255;\red26\green26\blue26;\red255\green255\blue255;\red39\green40\blue50;
}
{\*\expandedcolortbl;;\cssrgb\c13333\c13333\c13333;\cssrgb\c100000\c100000\c100000;\cssrgb\c20392\c20784\c25490;
}
\margl1440\margr1440\vieww28300\viewh15040\viewkind0
\deftab720
\pard\pardeftab720\parhyphenfactor20\partightenfactor0
\f0\fs32 \cf2 \cb3 \expnd0\expndtw0\kerning0
CPython implementation detail: CPython currently uses a reference-counting scheme with (optional) delayed detection of cyclically linked garbage, which collects most objects as soon as they become unreachable, but is not guaranteed to collect garbage containing circular references.\
\
What is a reference-counting scheme?\
It refers to a memory management technique where each object in a programming language implementation, such as CPython, keeps track of the number of references pointing to it. \
Whenever a reference is created to an object, its reference count is increased, and when a reference is deleted or goes out of scope, the reference count is decreased. \
\
What is a reference?\
In the context of memory management, a "reference" refers to an identifier or value that allows access to an object in a programming language. \
It is a way to refer to or point to the memory location where an object is stored.\
\
What is the advantage of reference-counting scheme?\
The advantage of the reference-counting scheme is that it allows objects to be deallocated immediately when they are no longer needed. \
It ensures efficient memory management because objects can be freed as soon as their reference count reaches zero, without the need for more complex garbage collection algorithms.\
\
What is a garbage?\
In the context of memory management, "garbage" refers to objects that are no longer reachable or used by the program but still occupy memory. \
This typically occurs when objects are created dynamically during program execution but are not properly deallocated or no longer accessible. \
Garbage collection is the process of identifying and reclaiming memory occupied by such unused objects, making it available for reuse. \
The reference-counting scheme used by CPython helps in automatically deallocating most objects as soon as they become unreachable. \
However, in the case of circular references, where objects refer to each other in a loop, additional mechanisms are required to detect and collect such cyclically linked garbage. It\'92s called "delayed detection of cyclically linked garbage" to collect and deallocate objects that are involved in cyclic references.\
\
\
\
What is a __blabla__(): method?\
In Python, the following are special attributes (also known as dunder attributes) that can be accessed on objects or functions.\
These special attributes provide additional information or access to specific properties of objects in Python. \
\
What is the advantages of the dunder method?\
Overall, dunder attributes provide flexibility, customization, and enhanced functionality to Python objects and classes. \
They contribute to the expressive nature of the language and enable powerful features like operator overloading and introspection.\
\
Convention: Dunder attributes follow a specific naming convention, starting and ending with double underscores (__). This convention makes them easily recognizable and distinguishes them from regular attributes.\
Customization: Dunder attributes allow you to customize and define the behavior of objects and classes. By implementing specific dunder methods, you can change how objects behave in certain situations, such as arithmetic operations, string representation, comparisons, and more.\
Operator Overloading: Dunder attributes enable operator overloading, allowing objects to participate in built-in operations like addition (+), subtraction (-), equality (==), and more. This makes it possible to define meaningful operations for custom classes.\
Introspection: Dunder attributes provide a way to introspect and access information about objects and classes. For example, name and doc allow you to retrieve the name and documentation of an object. This introspection capability is useful for debugging, documentation generation, and code analysis.\
Integration with Language Features: Dunder attributes seamlessly integrate with various language features, such as iteration (with iter), context managers (with enter and exit), attribute access (with getattr, setattr), and more. This allows you to leverage the full power of the Python language in your classes.\
Code Readability: By following the conventions for dunder attributes, your code becomes more readable and understandable by other Python developers. They can easily recognize and understand the purpose of these special attributes.\
\
\
\
What is a Von Neumann\'92s model of a \'93stored program computer\'94?\
Von Neumann's model of a "stored program computer" is a fundamental concept in computer architecture that describes the organization and operation of modern digital computers.\
It describes a computer architecture where instructions and data are stored together in memory, enabling the execution of instructions as data, and forming the basis of programmable digital computers.\
The distinguishing feature of Von Neumann's model is that both data and instructions are stored in the same memory. This means that the instructions that govern the computer's operations can be treated as data and manipulated like any other type of information. This concept, known as the "stored program concept," allows for the flexibility and programmability of modern computers.\
\
\
\
What is the Havard Model?\
\
\
\pard\pardeftab720\partightenfactor0
\cf4 \cb1 What is the difference between identity and type?\
Identity: \
The identity of an object is a unique identifier that remains constant throughout the object's lifetime. \
It can be thought of as the object's address in memory. \
Python provides a built-in function called id() that returns an integer representing the identity of an object. \
The identity never changes once the object is created, and no two objects can have the same identity at the same time.\
Type: \
The type of an object defines the category or class to which the object belongs. \
It determines the behavior of the object and the operations that can be performed on it. \
In Python, the type of an object is determined by its class, which defines the object's characteristics and behavior. \
The type of an object can be obtained using the type() function.\
\
To summarize, the identity of an object is a unique identifier associated with its memory location, while the type of an object defines its category or class, determining its behavior and the operations that can be performed on it.\
\
\
\
The important distinction between immutability and having an unchangeable value in the context of container objects that reference mutable objects in Python.\
In Python, immutability refers to the property of an object that prevents its internal state or structure from being modified after it is created. Immutable objects, such as integers, strings, and tuples, cannot be changed once they are created. However, when an immutable container object (like a tuple or a frozenset) contains a reference to a mutable object (such as a list or a set), the value of the mutable object can be modified even though the container object itself cannot be changed.\
So, while the value of the mutable object can be altered, the container object is still considered immutable because its internal structure (the collection of objects it contains) cannot be changed. The container object cannot be modified to add, remove, or replace elements, but the mutable object it references can be modified independently.\
Therefore, the concept of immutability is more subtle than simply having an unchangeable value. It refers to the inability to modify the structure or internal state of an object, but it doesn't necessarily guarantee that all the objects referenced by an immutable container are themselves immutable.\
\
\
\
What is a close() method in Python?\
The close() method is typically invoked on an object representing the file or resource. \
Calling the close() method can release the associated system resources and ensure that any buffered data is written to the disk.\
\
It's important to note that closing a file or resource is good practice to free up system resources and prevent any potential issues. Failing to close resources properly can result in resource leaks and may lead to unexpected behavior in your program.\
\
\
\
\'93try...finally\'94 statement:\
The try...finally statement is used to ensure that certain code is always executed, regardless of whether an exception occurs or not. \
The code within the try block is executed, and if an exception occurs, it can be caught and handled using an appropriate except block. After the try block (and any associated except blocks), the code within the finally block is executed, ensuring that it always runs, regardless of exceptions. This is useful for cleaning up resources or releasing locks, even if an exception occurs.\cf2 \cb3 \
\pard\pardeftab720\parhyphenfactor20\partightenfactor0
\cf2 \
\
\
\'93with\'94 statement:\
The with statement provides automatic resource management, improves code readability, handles exceptions effectively, and allows for the creation of custom context managers. It is a recommended approach for managing resources that need proper initialization and cleanup, such as files, database connections, network sockets, and more. By using the with statement, you can ensure that your code is more robust, maintainable, and less prone to resource leaks and error handling issues.\
\
\
\
What is a container?\
A container refers to an object that can hold multiple other objects or values. \
Examples of containers in Python include tuples, lists, dictionaries, sets, and other collection types.\
Containers are used to store and organize multiple objects or values together. They provide a way to group related data and operate on them as a whole. \
\
\
\
What is a type hierarchy?\
The type hierarchy in Python refers to the organization and relationships among different types or classes in the Python programming language. \
It defines how types are related to each other and how they inherit attributes and behaviors from their parent types.\
the type hierarchy in Python provides a structured organization of types, allowing for code reuse, inheritance, and polymorphism, which are fundamental principles of object-oriented programming.\
\
\
\
## The attached file HW7_test.py provides an example on how dunder method works. Don\'92t forget to check it out.}