Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 5.1 Metaprogramming
- = 5.1 Metaprogramming == Introduction to metaclasses Metaprogramming is a programming technique in whic... Another example of metaprogramming is the **metaclass** concept, which is one of the most advanced con... en of Python**, expressed his feelings about metaclasses in the **comp.lang.python** newsgroup on 12/22/2002: //[metaclasses] are deeper magic than 99% of users should eve
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- expresses the fundamental relationships between classes: superclasses (parents) and their subclasses (descendants). Inheritance creates a class hierarchy. Any object bound to a specific level of class
- 1.2 Working with class and instance data – instance variables
- = 1.2 Working with class and instance data – instance variables == Instance variables This kind of vari... are closely connected to the objects (which are class instances), not to the classes themselves. To get access to the instance variable, you should address... ssed in the code presented below. <code python> class Demo: def __init__(self, value): sel
- 2.6 Abstract classes
- = 2.6 Abstract classes Python is considered to be a very flexible programming language, but that doesn’... impose a set of functionalities or an order in a class hierarchy. When you develop a system in a group ... have some means of establishing requirements for classes in matters of interfaces (methods) exposed by each class. == What is an abstract class? An **abstract cla
- 2.5 Different faces of Python methods
- strates the idea presented above. <code python> class Example: def __init__(self, value): ... le2.get_internal()) </code> Each of the Example class objects has its own copy of the instance variabl... <code ; output> 10 99 </code> == The static and class methods Two other types of method can also be used in the Object Oriented Approach (OOP): * class methods; * static methods. These alternative
- 1.1 Classes, Instances, Attributes, Methods — introduction
- = 1.1 Classes, Instances, Attributes, Methods — introduction == Introduction to Object-Oriented Program... should agree on the following definitions: * class — an idea, blueprint, or recipe for an instance; * instance — an instantiation of the class; very often used interchangeably with the term '... ates of instances; * attribute — any object or class trait; could be a variable or method; * method
- 2.4 Decorators
- thon is able to decorate functions, methods, and classes. The decorator's operation is based on wrappi... al function with a new "decorating" function (or class), hence the name "decoration". This is done by p... The same principle is applied when we decorate classes. We'll talk about this a bit later. So from n... m 'decorator' will be understood as a decorating class or a decorating function. Decorators are used t
- 2.8 Composition vs Inheritance - two ways to the same destination
- lowing the inheritance concept when modeling our classes to represent real-life issues. Inheritance is ... ramming that models a tight relation between two classes: the base class and the derived class, called a subclass. The result of this relation is a subclass class that inher
- 2.9 Inheriting properties from built-in classes
- = 2.9 Inheriting properties from built-in classes Python gives you the ability to create a class that inherits properties from any Python built-in class in order to get a new class that can enrich the parent's attributes or methods. As a result, your new
- 2.1 Python core syntax
- str(), len() * reflexion – isinstance(), issubclass() and a few more elements. Python allows us to... agine the following situation: you've created a class that represents a person; each instance of the class owns a set of attributes describing a person: ag... at does it mean to add two objects of the Person class? Well, it depends on the domain of your applicat
- 2.7 Encapsulation
- d methods that work on those attributes within a class. Encapsulation is used to hide the **attributes** inside a class like in a **capsule**, preventing unauthorized p... licly accessible **methods** are provided in the class **to access** the values, and other objects call... e attributes; * in Python, you can change your class implementation from a class that allows simple a
- 3.1 Advanced techniques of creating and serving exceptions
- d from BaseException, the most general exception class. And this approach tells you that you can also create your own specific exception classes – the only constraint is: you have to subclass BaseException or any other derived exception class. == Exception handling When you suspect that the
- 4.2 Serialization of Python objects using the pickle module
- o avoid cycles!) * references to functions and classes, but not their definitions. Let's pickle our ... should follow the same order. <code ; output> <class 'dict'> {'EUR': {'code': 'Euro', 'symbol': '€'},... 'JPY': {'code': 'Japanese yen', 'symbol': '¥'}} <class 'list'> ['a', 123, [10, 100, 1000]] </code> A... ntermediate object type, used to preserve data: <class 'bytes'> A type of deserialized object: <class '
- 2.3 Extended function argument syntax
- amed *args and %%**%%kwargs) should be put as the last two parameters in a function definition. Their n... 50, argument2='66') </code> <code ; output> 10 <class 'int'> 20 <class 'str'> (40, 60, 30) <class 'tuple'> {'argument1': 50, 'argument2': '66'} <class 'dict'> </code> As y
- 4.1 Shallow and deep copy operations
- ains other objects, like lists, dictionaries, or class instances). <code python> print("Part 1") print... y of a compound object (list, dictionary, custom class instance) you should make use of deep copy, whic... zed when you want to copy dictionaries or custom class objects. The code on the right presents the cod... copy a_dict = { 'first name': 'James', 'last name': 'Bond', 'movies': ['Goldfinger (1964)