Cerca

Heus ací els resultats de la cerca.

2.1 Python core syntax
75 Resultats, Darrera modificació:
n strings, lists, integers, and floats. It’s natural for us to formulate expressions using algebraic s... every elevator has safety limits regarding the total weight it can lift. In this case, the '+' operat... s and return the corresponding result. If the total sum of the weights of the Person class objects do... on, these magic methods are sometimes called special purpose methods, because these methods are design
2.4 Decorators
53 Resultats, Darrera modificació:
orator's operation is based on wrapping the original function with a new "decorating" function (or cla... e "decoration". This is done by passing the original function (i.e., the **decorated** function) as a ... ers of the decorated function and perform additional actions and that make it a real decorating function. The same principle is applied when we decorate
3.1 Advanced techniques of creating and serving exceptions
33 Resultats, Darrera modificació:
the execution of a program that disrupts the normal flow of the program's instructions. Plan for the... , it: * stops your program; * creates a special kind of data, called an **exception**. Of course,... This is possible due to the fact that all potential exceptions have their unambiguous names, so you c... d that is why it is so important to know how to deal with exceptions. Python comes with 63((This numb
2.9 Inheriting properties from built-in classes
26 Resultats, Darrera modificació:
object? Imagine that you need to collect the serial numbers of sold tickets. Sound reasonable enough?... nding with ineligible element failed') print('Final result:', int_list) </code> Something that’s wo... s. To make our newly-created class fully functional, it’s necessary to deliver implementations for th... ailed Extending with ineligible element failed Final result: [49, 22, 2, 3] </code> In the next examp
2.6 Abstract classes
25 Resultats, Darrera modificació:
ract methods. When we’re designing large functional units, in the form of classes, we should use an a... development is finished. Let's start with a typical class that can be instantiated: <code python> cla... odule containing the ABC class instead of your local file. This could cause some confusion – why does ... formation about the scanner (max. resolution, serial number) * Create an abstract class representing
1.2 Working with class and instance data – instance variables
24 Resultats, Darrera modificació:
= Demo(200) print("d1's instance variable is equal to:", d1.instance_var) print("d2's instance variable is equal to:", d2.instance_var) </code> - **%%__init__%%... e hunting for bugs! The snippet contains additional comments for direct explanations. <code python> ... r class variable is used to keep track of the serial numbers (which in fact are also counters) of part
2.5 Different faces of Python methods
22 Resultats, Darrera modificació:
def __init__(self, value): self.__internal = value def get_internal(self): return self.__internal example1 = Example(10) example2 = Example(99) print(example1.get_internal()) print(example2.get_internal()) </code> Each o
2.8 Composition vs Inheritance - two ways to the same destination
17 Resultats, Darrera modificació:
concept when modeling our classes to represent real-life issues. Inheritance is a great concept, one ... base class for them, to which we transfer identical methods and properties. This will facilitate test... tom, like tree roots, not branches. The most general, and the widest, class is always at the top (the ... es) you can create a huge, complex, and hierarchical structure of classes. This hierarchy would be ha
2.3 Extended function argument syntax
16 Resultats, Darrera modificació:
eywords to all argument values, otherwise positional ones are the first ones on the arguments list. N... s that can accept any arbitrary number of positional arguments and keyword arguments. So far we've be... de. How is it possible for Python functions to deal with a variable number of arguments? Can we prepa... e'll tame them in a short moment. These two special identifiers (named *args and %%**%%kwargs) should
4.1 Shallow and deep copy operations
16 Resultats, Darrera modificació:
aking use of variables. As variables are fundamental elements that allow us to cope with objects, let'... should start with the ''%%'=='%%'' operator as usual. This operator compares the values of both operan... modify without automatically modifying the original at the same time. Let's have a look at the following code. Its intention is to: * make a real, independent copy of ''a_list'', (not just a copy
1.1 Classes, Instances, Attributes, Methods — introduction
13 Resultats, Darrera modificació:
lows programmers to model entities representing real-life objects. Moreover, OOP allows programmers to... interactions between objects in order to solve real-life problems in an efficient, comfortable, exten... d valuable data in attributes relevant to individual objects; * it owns and shares methods used to p... cipe for an instance. The class is something virtual, it can contain lots of different details, and th
2.7 Encapsulation
12 Resultats, Darrera modificació:
ncapsulation Encapsulation is one of the fundamental concepts in object-oriented programming (amongst ... ods might not realize if it is "talking" to the real attributes or to the methods controlling access t... objects. Let's start with a few analogies from real life: Imagine a washing machine door ( **object**... y** into the tank ( **object** ) exceeding the total tank capacity, or request setting the liquid leve
5.1 Metaprogramming
11 Resultats, Darrera modificació:
of precise automation must be provided. The typical use cases for metaclasses: * logging; * regi... se classes will be instances of the **type** special class, which is the default **metaclass** respons... ting them. We should get familiar with some special attributes: * ''%%__name__%%'' – inherent for ... example that dynamically creates a fully functional class is presented in the right pane. <code pyth
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
9 Resultats, Darrera modificació:
pillar of OOP Inheritance is one of the fundamental concepts of object oriented programming, and expresses the fundamental relationships between classes: superclasses (pare... erclass. Conversely, each superclass is more general (more abstract) than any of its subclasses. Note ... y for now, as we're going to show you how the mutual relations between the super- and subclasses work.
4.3 Making Python objects persistent using the shelve module
6 Resultats, Darrera modificació:
hlv', flag='w') </code> The meaning of the optional flag parameter: {{:info:cursos:pue:python-pcpp1:p... t access to the elements (contrary to the sequential access to items when we use pickles). <code pytho... shelve['USD']) new_shelve.close() </code> The final code is presented in the right pane. <code python... object as a Python dictionary, with a few additional notes: * the keys must be strings; * Python
4.2 Serialization of Python objects using the pickle module
3 Resultats, Darrera modificació: