Cerca

Heus ací els resultats de la cerca.

4.1 Shallow and deep copy operations
46 Resultats, Darrera modificació:
forms any kind of data processing without making use of variables. As variables are fundamental elemen... of copying them. When you spot the following clause: <code python> a_list = [ 1, 'New York', 100] </c... used, so evaluation of the right side of the clause takes precedence over the left side.) * At fir... s rarely used in applications. More often you’ll use it to debug the code or to experiment while copyi
3.1 Advanced techniques of creating and serving exceptions
42 Resultats, Darrera modificació:
ial kind of data, called an **exception**. Of course, this exception is an object. Both of these activities are called **raising an exception**. We can s... message sent to the console by Python; * otherwise, if the exception is taken care of and **handled*... on handling When you suspect that the code may raise an exception, you should use the ''try: problemat
2.6 Abstract classes
37 Resultats, Darrera modificació:
at doesn’t mean that there are no controls to impose a set of functionalities or an order in a class h... sed by the abstract class. == Why do we want to use abstract classes? The very important reason is: w... a is to design an abstract class representing a base music format and corresponding methods for “open”... eeds subclasses to provide implementations for those abstract methods which are declared in the abstra
2.4 Decorators
34 Resultats, Darrera modificació:
urns a function that can be called later. Of course, the **decorating** function does more, because it can take the parameters of the decorated function ... ze some examples before we get down to the next dose of theory. So, let's create a function – ''simpl... of arguments passed. In such a situation, we can use the *args and %%**%%kwargs concepts. We can also
2.9 Inheriting properties from built-in classes
32 Resultats, Darrera modificació:
arent or even parents and you can still access those attributes and methods. Later, you can override ... if type(value) is not int: raise ValueError('Not an integer type') def __seti... rter, cleaner and easier to maintain. We'll make use of this method a few times. In case the argument's type is not an integer, a ValueError exception is
2.1 Python core syntax
30 Resultats, Darrera modificació:
rator, but on respective data types. Now, we'll use the same function ''len()'' to get a number of el... operators when applied to our objects, so we can use core operators on our objects. Let's imagine the... egarding the total weight it can lift. In this case, the '+' operator, when applied to two objects, s... er to apply it to the operands (objects). Of course, the '+' operator is just a handy example, and la
2.8 Composition vs Inheritance - two ways to the same destination
30 Resultats, Darrera modificació:
odels a tight relation between two classes: the base class and the derived class, called a subclass. ... s **all** methods and **all** properties of the base class, and allows a subclass to extend everything that has been inherited. By extending a base class, you are creating a more specialized class. Moreover, we say that these classes are **tightly** coupled. **Inheritance**
2.5 Different faces of Python methods
29 Resultats, Darrera modificació:
elf'' allows you to refer to the instance. Of course, it follows that in order to successfully use the instance method, the instance must have previously ... eter ''self'' was chosen arbitrarily and you can use a different word, but you must do it consistently... OOP): * class methods; * static methods. These alternative types of method should be understood
2.7 Encapsulation
25 Resultats, Darrera modificació:
f bundling attributes and methods that work on those attributes within a class. Encapsulation is used... to access** the values, and other objects call those methods to retrieve and modify the values within ... something (it could be a legacy code) that makes use of your objects. Let's start with a few analogie... or the account balance. But you can always make use of some dedicated interfaces (methods like a mobi
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
19 Resultats, Darrera modificació:
d with more prudence than single inheritance because: * a single inheritance class is always simple... named D, derived from B and C (or C and B, as these two variants mean different things in Python) Can... his is the result of the MRO algorithm. In our case: * **class D** does not define the method ''in... method should print a message indicating its purpose and origin, like: * 'print() method from Printe
4.3 Making Python objects persistent using the shelve module
19 Resultats, Darrera modificació:
r of all the elements placed into a file or database, or sent via a network. There is another handy m... th a key. The keys must be ordinary strings, because the underlying database (dbm) requires strings. Therefore, you can open your shelved data file and a... create an object representing a file-based database: <code python> import shelve my_shelve = shelve.o
5.1 Metaprogramming
19 Resultats, Darrera modificació:
protocol. It may look like syntactic sugar, because in many cases metaprogramming allows programmers ... technique could be used for tool preparation; those tools could be applied to your code to make it fo... the most advanced concepts presented in this course. Tim Peters, the Python guru who authored the *... erstanding Python metaclasses is worthwhile, because it leads to a better understanding of what is hap
4.2 Serialization of Python objects using the pickle module
13 Resultats, Darrera modificació:
ll learn how to persist Python objects for later use. **Pickling** is the process of preserving or ex... ing the output of your data processing for later use? The simplest way to persist outcomes is to gene... m of bytes to store the object in a file or database, or to transmit it via a network. This byte strea... t the object in another Python script. This reverse process is called **deserialization**. Python ob
2.3 Extended function argument syntax
12 Resultats, Darrera modificació:
assigning keywords to all argument values, otherwise positional ones are the first ones on the argumen... n't worry, we'll tame them in a short moment. These two special identifiers (named *args and %%**%%kw... ion definition. Their names could be changed because it is just a convention to name them 'args' and '... rder of the parameters and leading asterisks. Those two special parameters are responsible for handli
1.1 Classes, Instances, Attributes, Methods — introduction
11 Resultats, Darrera modificació:
ach is present in most computer applications because it allows programmers to model entities represent... n a web browser created with OOP, and even the mouse cursor image is displayed using an application cr... everything in Python organized as objects? Because an object is a very useful culmination of all the... ring this and the next module: * creation and use of decorators; * implementation of core syntax;
1.2 Working with class and instance data – instance variables
8 Resultats, Darrera modificació: