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
- 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... er application, intended to support multiple file formats. Some of the formats are known now, but some are not yet known. The idea is to design an abstract
- 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... ss definitions are read to create classes, well before classes are instantiated. Metaclasses usually e
- 1.2 Working with class and instance data – instance variables
- an be done during the object's initialization, performed by the __init__ method, or later at any moment... **%%__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:
- 2.4 Decorators
- e the parameters of the decorated function and perform additional actions and that make it a real decor... a decorating function. Decorators are used to perform operations before and after a call to a wrapped object or even to prevent its execution, depending on... Function decorators Let's analyze some examples before we get down to the next dose of theory. So, let
- 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
- 3.1 Advanced techniques of creating and serving exceptions
- normal flow of the program's instructions. Plan for the module: * short introduction to exceptions... re of the raised exception, the program will be **forcibly terminated**, and you will see an error mess... in exceptions, and they can be represented in the form of a tree-shaped hierarchy. The reason for this is that exceptions are inherited from BaseException,
- 2.1 Python core syntax
- trings, lists, integers, and floats. It’s natural for us to formulate expressions using algebraic symbols representing operators, or to get a number of elem... g. This is Python core syntax – an ability to perform specific operations **on different** data types, when operations are formulated using **the same** operators or instructio
- 4.1 Shallow and deep copy operations
- to imagine writing a piece of Python code that performs any kind of data processing without making use ... ger which is guaranteed to be unique and constant for this object during its lifetime. Two objects with... ct of this infrequent use is that some developers forget about its existence and create their own varia... r compares the values of both operands and checks for value equality. So here we witness a values compa
- 2.5 Different faces of Python methods
- now, we’ve been implementing methods that have performed operations on the instances (objects), and in ... variables, e.g., to a class variable containing information about the number of created instances or th... l(cls): return '# of objects created: {}'.format(cls.__internal_counter) print(Example.get_int... arameter to access the class variable appropriate for the Example class. Of course, you can use the re
- 2.8 Composition vs Inheritance - two ways to the same destination
- on. Examples: * a Laptop **is a** (specialized form of) Computer; * a Square **is a** (specialized form of) Figure; * a Hovercraft **is a** Vehicle. ... heritance is to reuse the code. If two classes perform similar tasks, we can create a common base class for them, to which we transfer identical methods and
- 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 ... ia a network. This byte stream contains all the information necessary to reconstruct the object in anot
- 1.1 Classes, Instances, Attributes, Methods — introduction
- r to solve real-life problems in an efficient, comfortable, extendable, and well-structured manner. Im... tions: * class — an idea, blueprint, or recipe for an instance; * instance — an instantiation of t... bjects; * it owns and shares methods used to perform actions. * The following issues will be addre... ass expresses an idea; it’s a blueprint or recipe for an instance. The class is something virtual, it c
- 2.7 Encapsulation
- values within the object. This can be a way to enforce a certain amount of privacy for the attributes. This picture presents the idea: direct access to th... always invoke methods, acting like proxies, to perform some actions on the attributes. {{ :info:cursos... ncapsulated attribute; * it should be defined before the method responsible for setting the value of
- 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... all unexpected arguments that were passed in the form of keyword=value pairs. Likewise, %%**%%kwargs c