Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.4 Decorators
- ider a function that accepts arguments and should also be decorated. Decorators, which should be unive... n use the *args and %%**%%kwargs concepts. We can also employ a closure technique to persist arguments... which the decorator will be more generic – we’ll allow you to pass the packing material in the argume... print("We'll pack fruits:", args) pack_books('Alice in Wonderland', 'Winnie the Pooh') pack_toys('
- 2.5 Different faces of Python methods
- s worth emphasizing and remembering that ''self'' allows you to refer to the instance. Of course, it f... __internal%%'', and the ''get_internal()'' method allows you to read the instance variable specific to... c and class methods Two other types of method can also be used in the Object Oriented Approach (OOP): * class methods; * static methods. These alternative types of method should be understood as
- 2.6 Abstract classes
- ract methods**. * The programmer has to deliver all method definitions and the completeness would be... reason is: we want our code to be polymorphic, so all subclasses have to deliver a set of their own me... g only abstract methods – some of the methods can already be defined, but if any of the methods is an ... loper has implemented a subclass that overrides __all__ abstract methods. When we’re designing large
- 2.8 Composition vs Inheritance - two ways to the same destination
- this relation is a subclass class that inherits **all** methods and **all** properties of the base class, and allows a subclass to extend everything that has been inherited. ... case of changes. In case of any problems, it will also be easier to find the cause of the error. As a
- 2.9 Inheriting properties from built-in classes
- lt, your newly-created class has the advantage of all of the well-known functionalities inherited from... based on the Python list implementation and will also validate the type of elements that are about to... s to the object. What have we not delivered? * All the remaining methods have remained unchanged, s... alue). Well, what is this IBAN then? IBAN is an algorithm used by European banks to specify account
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- d to a specific level of class hierarchy inherits all the traits (methods and attributes) defined insi... ng a new class, not from scratch, but by using an already defined repertoire of traits. The new class inherits (and this is the key) all the already existing equipment, but is able to add some new features if needed. Each subclass is mo
- 2.3 Extended function argument syntax
- low function definition; * functions might have already defined default values for some parameters, so we do not have to pass all arguments as missing arguments, complete with de... ents in any order if we are assigning keywords to all argument values, otherwise positional ones are t... nt(3) print(1, 20, 10) print('--', '++') </code> All presented invocations of the **print()** functio
- 2.7 Encapsulation
- ect attribute should not be possible, but you can always invoke methods, acting like proxies, to perfo... hange your class implementation from a class that allows simple and direct access to attributes to a c... . You have a set of controls ( **methods** ) that allow you to manage your laundry, or even see it (ma... ertain limits or the account balance. But you can always make use of some dedicated interfaces (method
- 3.1 Advanced techniques of creating and serving exceptions
- **raising an exception**. We can say that Python always raises an exception (or that an exception has... n continue. Python provides effective tools that allow you to **observe exceptions, identify them and... iciently**. This is possible due to the fact that all potential exceptions have their unambiguous name... categorize them and react appropriately. You may already have met an exception error message like the
- 1.1 Classes, Instances, Attributes, Methods — introduction
- present in most computer applications because it allows programmers to model entities representing real-life objects. Moreover, OOP allows programmers to model interactions between obj... Because an object is a very useful culmination of all the terms described above: * it is an indepen... n contain lots of different details, and there is always one class of any given type. Think of a class
- 1.2 Working with class and instance data – instance variables
- instance variable of any object has no impact on all the remaining objects. Instance variables are co... nstance. Because it is owned by the class itself, all class variables are shared by all instances of the class. They will therefore generally have the sam... iable' d1 = Demo() d2 = Demo() # both instances allow access to the class variable print(d1.class_va
- 5.1 Metaprogramming
- le the code is being executed, and you might have already experienced it while implementing decorators... ctic sugar, because in many cases metaprogramming allows programmers to minimize the number of lines o... ines the behavior of certain objects, a metaclass allows for the customization of class instantiation.... e defined by their inherent classes. The example also shows that we can create our own classes, and t
- 2.1 Python core syntax
- ar we have been using Python core operations that allow us to operate on strings, lists, integers, and... t’s natural for us to formulate expressions using algebraic symbols representing operators, or to get ... d integers and we know what the result should be, all done by using the “+” operator, but on respectiv... ), issubclass() and a few more elements. Python allows us to employ operators when applied to our ob
- 4.1 Shallow and deep copy operations
- ables. As variables are fundamental elements that allow us to cope with objects, let's talk in detail ... but just created a new label that references the already created list. This interesting behavior wil... referencing the same object, the result would be also 'True'. To check whether both operands refer t... stead populates ''b_list'' with references to the already existing objects. {{ :info:cursos:pue:pytho
- 4.2 Serialization of Python objects using the pickle module
- nsmit it via a network. This byte stream contains all the information necessary to reconstruct the obj... s called **deserialization**. Python objects can also be serialized using a module called 'pickle', a... ly the object is persisted but not its definition allowing us to determine the attribute layout: <cod... )'' or ''loads()'' functions of ''pickle'' should already know the function/class definition. A few a