Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.4 Decorators
- = 2.4 Decorators A decorator is one of the design patterns that describes the structure of related obj... , hence the name "decoration". This is done by passing the original function (i.e., the **decorated** ... dose of theory. So, let's create a function – ''simple_hello()'' is one of the simplest functions we could think of. We'll decorate it in a moment. <co
- 2.8 Composition vs Inheritance - two ways to the same destination
- = 2.8 Composition vs Inheritance - two ways to the same destination So far we've been using and following the inheritance concept when mode... ance is to reuse the code. If two classes perform similar tasks, we can create a common base class for... anges. In case of any problems, it will also be easier to find the cause of the error. As a result, y
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- all the traits (methods and attributes) defined inside any of the superclasses. This means that inher... f building a new class, not from scratch, but by using an already defined repertoire of traits. The ne... ython-pcpp1:pasted:20231013-035718.png }} A very simple example of two-level inheritance is presented... cle** classes. == Inheritance and polymorphism — Single inheritance vs. multiple inheritance There ar
- 4.2 Serialization of Python objects using the pickle module
- = 4.2 Serialization of Python objects using the pickle module In this section, you will learn how to persist Python objects for later use. **Pickling** is ... d with the 'pickled' adjective. Have you ever considered saving the output of your data processing for later use? The simplest way to persist outcomes i
- 2.7 Encapsulation
- ncapsulation is used to hide the **attributes** inside a class like in a **capsule**, preventing unaut... zed parties' direct access to them. Publicly accessible **methods** are provided in the class **to acc... t access to the object attribute should not be possible, but you can always invoke methods, acting lik... our class implementation from a class that allows simple and direct access to attributes to a class th
- 3.1 Advanced techniques of creating and serving exceptions
- * introduction to chained exceptions; * analysis of the traceback object of each exception. == E... on When Python executes a script and encounters a situation that it cannot cope with, it: * stops y... object. Both of these activities are called **raising an exception**. We can say that Python always r... fy them and handle them efficiently**. This is possible due to the fact that all potential exceptions
- 5.1 Metaprogramming
- l class, which is the default **metaclass** responsible for creating classes. Let's perform one more ... These observations lead us to the following conclusions: * metaclasses are used to create classes; ... the class and state the class namespace. A very simple example, when both ''bases'' and ''dictionary... ict__) </code> As a result, we have created the simple class “Dog”. <code ; output> The class name
- 2.1 Python core syntax
- = 2.1 Python core syntax So far we have been using Python core operations that allow us to operate on ... nd floats. It’s natural for us to formulate expressions using algebraic symbols representing operators, or to get a number of elements in a sequence or di... d we know what the result should be, all done by using the “+” operator, but on respective data types.
- 2.9 Inheriting properties from built-in classes
- g argument types. As we have delegated this responsibility to only one method, the code will be shorter, cleaner and easier to maintain. We'll make use of this method a fe... ch is a magic method (mind the underscores) responsible for inserting (overwriting) an element at a given position. This method calls the check_value_type() met
- 2.5 Different faces of Python methods
- rameter, which is their hallmark. It’s worth emphasizing and remembering that ''self'' allows you to r... le specific to the indicated instance. This is possible thanks to using ''self''. The name of the parameter ''self'' was chosen arbitrarily and you can use a different word, but you must do it consistently in your code. It follows from the conventi
- 2.6 Abstract classes
- = 2.6 Abstract classes Python is considered to be a very flexible programming language, but that doesn... bstract class? An **abstract class** should be considered a blueprint for other classes, a kind of contract between a __class designer__ and a __programmer__: * the class designer sets requirements regarding methods that must be
- 1.2 Working with class and instance data – instance variables
- - we instantiate the class twice, each time passing a different value to be stored inside the object; - the print instructions prove the fact that in... Moreover, it lists the contents of each object, using the built-in __dict__ property that is present ... ce is created. To get access to a class variable, simply access it using the class name, and then prov
- 2.3 Extended function argument syntax
- quire a specific number of arguments with no exclusions; we have to pass a required number of argument... rs, so we do not have to pass all arguments as missing arguments, complete with defaults; parameters w... * we can pass arguments in any order if we are assigning keywords to all argument values, otherwise positional ones are the first ones on the arguments li
- 4.1 Shallow and deep copy operations
- llow and deep copy operations == Copying objects using shallow and deep operations In this module, you... Python code that performs any kind of data processing without making use of variables. As variables a... alk in detail about variables and objects, and possible ways of copying them. When you spot the follo... p1:pasted:20231026-143815.png }} (Note that an assignment statement is being used, so evaluation of t
- 1.1 Classes, Instances, Attributes, Methods — introduction
- bject-oriented approach is an evolution of good design practices that go back to the very beginning of... OP, and even the mouse cursor image is displayed using an application created with OOP. The same appli... chapter assumes that you are familiar with the basics of OOP, so to establish an understanding of com... t methods; * comparison of inheritance and composition; * attribute encapsulation; * exception c