Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.9 Inheriting properties from built-in classes
- the methods by delivering your own modifications for the selected methods. In the following example, ... , value) def extend(self, iterable): for element in iterable: IntegerList.chec... e have delivered: * a static, dedicated method for checking argument types. As we have delegated thi... a magic method (mind the underscores) responsible for inserting (overwriting) an element at a given pos
- 5.1 Metaprogramming
- dea was born and implemented in the early 1960s. For Python, code modifications can occure while the c... ut the truth is that this technique could be used for tool preparation; those tools could be applied to... e behavior of certain objects, a metaclass allows for the customization of class instantiation. The fu... tomation must be provided. The typical use cases for metaclasses: * logging; * registering classe
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- pass</code> All the presented classes are empty for now, as we're going to show you how the mutual re... hat: * the **Vehicle** class is the superclass for both the **LandVehicle** and **TrackedVehicle** c... nce scenario, any specified attribute is searched for first in the current class. If it is not found, t... fine the method ''info()'', so Python has to look for it in the class hierarchy; * **class D** is con
- 2.1 Python core syntax
- trings, lists, integers, and floats. It’s natural for us to formulate expressions using algebraic symbo... application. If you’re developing an application for an elevator, then you should remember that every ... gers, or even two Person class objects – it looks for the magic method responsible for the called function or operator in order to apply it to the operands
- 4.1 Shallow and deep copy operations
- ger which is guaranteed to be unique and constant for this object during its lifetime. Two objects with... r compares the values of both operands and checks for value equality. So here we witness a values compa... 626.png }} The 'copy' module contains a function for shallow copying: ''copy()''. Of course, you could say that for copying lists there is already the ''[:]'' notati
- 1.2 Working with class and instance data – instance variables
- **%%__init__%%** creates an instance_var variable for the instance. The keyword self is used to indicat... s variable is created coherently and individually for the instance to make it independent from other in... ng the built-in __dict__ property that is present for every Python object. <code python> class Demo: ... They will therefore generally have the same value for every instance; butas the class variable is defin
- 2.6 Abstract classes
- l to have some means of establishing requirements for classes in matters of interfaces (methods) expose... abstract class** should be considered a blueprint for other classes, a kind of contract between a __cla... ing a base music format and corresponding methods for “open”, “play”, “get details”, “rewind”, etc., to... ism. Your team should implement concrete classes for each format you'd like to support. Whenever new f
- 3.1 Advanced techniques of creating and serving exceptions
- normal flow of the program's instructions. Plan for the module: * short introduction to exceptions... n the form of a tree-shaped hierarchy. The reason for this is that exceptions are inherited from BaseEx... situation is typical when you have a good reason for the unifying behavior of one piece of code to act... ''%%__context__%%'' attribute, which is inherent for implicitly chained exceptions; the ''%%__cause__%
- 2.4 Decorators
- function </code> The last lines are responsible for both method invocations: <code python> decorated ... ould be mentioned that decorators are very useful for refactoring or debugging the code. <code python>... ifferent materials. We’ve also created functions for packaging different kinds of items, each decorate... code: <code python> # import module responsible for time processing from datetime import datetime #
- 2.5 Different faces of Python methods
- arameter to access the class variable appropriate for the Example class. Of course, you can use the re... vin): print('Ordinary __init__ was called for', vin) self.vin = vin self.brand ... ode: <code ; output> Ordinary __init__ was called for ABCD1234 Class method was called Ordinary __init__ was called for DEF567 ABCD1234 DEF567 NewBrand </code> As you c
- 4.2 Serialization of Python objects using the pickle module
- ion, you will learn how to persist Python objects for later use. **Pickling** is the process of preser... sidered saving the output of your data processing for later use? The simplest way to persist outcomes ... very simple thing to do way which is not suitable for persisting sets of different types of objects or ... this module, you can 'pickle' your Python objects for later use. The 'pickle' module is a very popular
- 2.7 Encapsulation
- n be a way to enforce a certain amount of privacy for the attributes. This picture presents the idea: ... t should be defined before the method responsible for setting the value of the encapsulated attribute, and before the method responsible for deleting the encapsulated attribute. Let's have ... e, and the class delivers the methods responsible for handling access to that attribute. The @property
- 1.1 Classes, Instances, Attributes, Methods — introduction
- tions: * class — an idea, blueprint, or recipe for an instance; * instance — an instantiation of t... ass expresses an idea; it’s a blueprint or recipe for an instance. The class is something virtual, it c... nally, your classes could be used as superclasses for newly derived classes (subclasses). Python’s cla... lf.weight, self.sex — containing different values for each object; * methods: %%__init__%%, walk, qua
- 2.8 Composition vs Inheritance - two ways to the same destination
- similar tasks, we can create a common base class for them, to which we transfer identical methods and ... m Vehicles own properties and methods responsible for informing the user of its mileage, starting and s... should apply to the ''tank()'' method responsible for fueling every vehicle object, so the polymorphism... developer's responsibility is to provide methods for both engine classes, named in the same way (here
- 2.3 Extended function argument syntax
- nctions might have already defined default values for some parameters, so we do not have to pass all ar... hen reading third-party code. How is it possible for Python functions to deal with a variable number o... ks. Those two special parameters are responsible for handling any number of additional arguments (plac... (it denotes a pointer) which could be misleading for you. Let's run the Python code presented in the