de

Cerca

Heus ací els resultats de la cerca.

2.4 Decorators
75 Resultats, Darrera modificació:
essage logging; * thread synchronization; * code refactorization; * caching. == Function decora... ould think of. We'll decorate it in a moment. <code python> def simple_hello(): print("Hello from simple function!") </code> <code python> def simple_decorator(function): print('We are about to call "{}"'.format(function
3.1 Advanced techniques of creating and serving exceptions
73 Resultats, Darrera modificació:
aised) when it has no idea what do to with your code. What happens next? * the raised exception ex... an exception error message like the following: <code ; output> IndexError: list index out of range </code> Sooner or later, every Pythonista will write a code that raises an exception, and that is why it is s
4.1 Shallow and deep copy operations
67 Resultats, Darrera modificació:
It’s hard to imagine writing a piece of Python code that performs any kind of data processing without... ing them. When you spot the following clause: <code python> a_list = [ 1, 'New York', 100] </code> {{ :info:cursos:pue:python-pcpp1:pasted:20231026-1438... ement is being used, so evaluation of the right side of the clause takes precedence over the left side
5.1 Metaprogramming
56 Resultats, Darrera modificació:
nd implemented in the early 1960s. For Python, code modifications can occure while the code is being executed, and you might have already experienced it ... programmers to minimize the number of lines of code to express a solution, in turn reducing developme... eparation; those tools could be applied to your code to make it follow specific programming patterns,
4.2 Serialization of Python objects using the pickle module
53 Resultats, Darrera modificació:
ring, an integer, and a list. When you run the code presented in the right pane, a new file should be created. Remember to run the code locally. <code python> import pickle a_dict = dict() a_dict['EUR'] = {'code':'Euro', 'symbol': '€'} a_dict['GBP'] = {'code':'
2.6 Abstract classes
45 Resultats, Darrera modificació:
sses? The very important reason is: we want our code to be polymorphic, so all subclasses have to deli... ble, you won’t have to rework your music player code, you’ll just have to deliver a class supporting t... n abstract class, and it needs subclasses to provide implementations for those abstract methods which ... hould use an abstract class. When we want to provide common implemented functionality for all implemen
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
42 Resultats, Darrera modificació:
l the traits (methods and attributes) defined inside any of the superclasses. This means that inherit... e of two-level inheritance is presented here: <code python>class Vehicle: pass class LandVehicle... s class TrackedVehicle(LandVehicle): pass</code> All the presented classes are empty for now, as... nt to call the method info(), which part of the code would be executed then? Python lets you implemen
2.9 Inheriting properties from built-in classes
39 Resultats, Darrera modificació:
ose attributes and methods. Later, you can override the methods by delivering your own modifications ... e problem and not on type control. Look at the code presented in the editor pane. <code python> class IntegerList(list): @staticmethod def chec... t failed') print('Final result:', int_list) </code> Something that’s worth commenting on is that we
1.2 Working with class and instance data – instance variables
35 Resultats, Darrera modificació:
nstance variable is created and accessed in the code presented below. <code python> class Demo: def __init__(self, value): self.instance_var ... ance variable is equal to:", d2.instance_var) </code> - **%%__init__%%** creates an instance_var var... h time passing a different value to be stored inside the object; - the print instructions prove the
2.5 Different faces of Python methods
31 Resultats, Darrera modificació:
the instance must have previously existed. The code in the editor demonstrates the idea presented above. <code python> class Example: def __init__(self, val... et_internal()) print(example2.get_internal()) </code> Each of the Example class objects has its own c... t word, but you must do it consistently in your code. It follows from the convention that //self// lit
2.3 Extended function argument syntax
28 Resultats, Darrera modificació:
most basic example is a **print()** function: <code python> print() print(3) print(1, 20, 10) print('--', '++') </code> All presented invocations of the **print()** fu... example can be presented with a list function: <code python> a_list = list() b_list = list(10, 20, 43,... , 23, 34, 23, 2) print(a_list) print(b_list) </code> Similarly to the **print()** function, the **lis
2.7 Encapsulation
28 Resultats, Darrera modificació:
butes within a class. Encapsulation is used to hide the **attributes** inside a class like in a **capsule**, preventing unauthorized parties' direct acce... concept has some interesting features: * the code calling the proxy methods might not realize if it... tand someone or something (it could be a legacy code) that makes use of your objects. Let's start wit
2.1 Python core syntax
24 Resultats, Darrera modificació:
propriate action. Look at the following simple code: <code python>number = 10 print(number + 20) </code> It is in fact translated to: <code python>number = 10 print(number.__add__(20))</code> Try running t
2.8 Composition vs Inheritance - two ways to the same destination
24 Resultats, Darrera modificació:
The primary use of inheritance is to reuse the code. If two classes perform similar tasks, we can cre... other words, the complete recipe is contained inside the class itself and all its ancestors; the objec... uring program runtime. Let's try to write some code to see how composition works. Look at the simple code presented in the editor pane. <code python> clas
1.1 Classes, Instances, Attributes, Methods — introduction
23 Resultats, Darrera modificació:
es with a minimum of new syntax and semantics: <code python> class Duck: def __init__(self, height... ef quack(self): return print('Quack') </code> In the code above, we have defined a class named Duck, consisting of some functionalities and attrib... . A class is a place which binds data with the code. If you run the code, there are no visible effec
4.3 Making Python objects persistent using the shelve module
18 Resultats, Darrera modificació: