Cerca

Heus ací els resultats de la cerca.

2.6 Abstract classes
174 Resultats, Darrera modificació:
ies or an order in a class hierarchy. When you develop a system in a group of programmers, it would be... **abstract methods**. * The programmer has to deliver all method definitions and the completeness w... ted by another, dedicated module. The programmer delivers the method definitions by __overriding__ the... ode to be polymorphic, so all subclasses have to deliver a set of their own method implementations in
2.7 Encapsulation
119 Resultats, Darrera modificació:
xample is a money bank; this time it’s a more IT-related example: When your money ( **attribute value... attributes **intentionally** as Python does not deliver true privacy. Why? Guido Van Rossum, best k... the behavior of a class representing a water or fuel tank: It would not be wise to pour any amount of... l tank capacity, or request setting the liquid level to a negative value. Python allows you to contro
2.8 Composition vs Inheritance - two ways to the same destination
90 Resultats, Darrera modificació:
ing and following the inheritance concept when modeling our classes to represent real-life issues. Inh... oundations of object-oriented programming that models a tight relation between two classes: the base class and the derived class, called a subclass. The result of this relation is a subclass class that inherits **all** me
2.1 Python core syntax
83 Resultats, Darrera modificació:
ols representing operators, or to get a number of elements in a sequence or dictionary. We are able t... se the same function ''len()'' to get a number of elements of a tuple, list, dictionary, or characters... xion – isinstance(), issubclass() and a few more elements. Python allows us to employ operators when... it mean to add two objects of the Person class? Well, it depends on the domain of your application.
2.9 Inheriting properties from built-in classes
76 Resultats, Darrera modificació:
ly-created class has the advantage of all of the well-known functionalities inherited from its parent ... methods. Later, you can override the methods by delivering your own modifications for the selected methods. In the following example, we’ll create an im... ion of our own list class, which will only accept elements of the integer type. But, wait – why might
4.3 Making Python objects persistent using the shelve module
54 Resultats, Darrera modificació:
4.3 Making Python objects persistent using the shelve module == Serialization of Python objects using the shelve module As you remember, the pickle module is us... lizing parties must abide by the order of all the elements placed into a file or database, or sent via... network. There is another handy module, called shelve, that is built on top of pickle, and implements
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
52 Resultats, Darrera modificació:
ented programming, and expresses the fundamental relationships between classes: superclasses (parents)... lass hierarchy. Any object bound to a specific level of class hierarchy inherits all the traits (metho... ed (or more specific) than its superclass. Conversely, each superclass is more general (more abstract)... 13-035718.png }} A very simple example of two-level inheritance is presented here: <code python>clas
1.1 Classes, Instances, Attributes, Methods — introduction
44 Resultats, Darrera modificació:
applications because it allows programmers to model entities representing real-life objects. Moreover, OOP allows programmers to model interactions between objects in order to solve re... ms in an efficient, comfortable, extendable, and well-structured manner. Imagine that the text you ar... es some specific and valuable data in attributes relevant to individual objects; * it owns and share
2.4 Decorators
43 Resultats, Darrera modificació:
design patterns that describes the structure of related objects. Python is able to decorate functions... theory. So, let's create a function – ''simple_hello()'' is one of the simplest functions we could t... corate it in a moment. <code python> def simple_hello(): print("Hello from simple function!") </code> <code python> def simple_decorator(function):
3.1 Advanced techniques of creating and serving exceptions
40 Resultats, Darrera modificació:
s, so you can categorize them and react appropriately. You may already have met an exception error me... most general exception class. And this approach tells you that you can also create your own specific ... ept'' clause will try to handle the problem in an elegant way. Let's look at typical try ... except s... rry additional information about the exception itself. The ''ImportError'' exception – raised when th
1.2 Working with class and instance data – instance variables
37 Resultats, Darrera modificació:
way. The word instance suggests that they are closely connected to the objects (which are class instances), not to the classes themselves. To get access to the instance variable, you s... le is created and accessed in the code presented below. <code python> class Demo: def __init__(self, value): self.instance_var = value d1 =
4.1 Shallow and deep copy operations
33 Resultats, Darrera modificació:
Specifically, you'll learn about: * object: label vs. identity vs. value; * the id() function and... ng use of variables. As variables are fundamental elements that allow us to cope with objects, let's t... inally a variable, which you should treat as a label or name binding, is created, and this label refers to a distinct place in the computer memory. What
2.5 Different faces of Python methods
31 Resultats, Darrera modificació:
ance methods, as the first parameter, take the ''self'' parameter, which is their hallmark. It’s worth emphasizing and remembering that ''self'' allows you to refer to the instance. Of course... . <code python> class Example: def __init__(self, value): self.__internal = value def get_internal(self): return self.__internal
5.1 Metaprogramming
27 Resultats, Darrera modificació:
f code to express a solution, in turn reducing development time. But the truth is that this technique... e it follow specific programming patterns, or to help you create a coherent API (Application Programmi... o authored the **Zen of Python**, expressed his feelings about metaclasses in the **comp.lang.python**... en class definitions are read to create classes, well before classes are instantiated. Metaclasses us
4.2 Serialization of Python objects using the pickle module
7 Resultats, Darrera modificació:
dle is associated with the file; * we consecutively read some portions of data and deserialize it wi... code python> import pickle def f1(): print('Hello from the jar!') with open('function.pckl', 'wb... type(data)) print(data) data() </code> Unfortunately, the result proves that no code was persisted: <... import pickle class Cucumber: def __init__(self): self.size = 'small' def get_size(
2.3 Extended function argument syntax
2 Resultats, Darrera modificació: