Cerca

Heus ací els resultats de la cerca.

2.4 Decorators
22 Resultats, Darrera modificació:
e classes. We'll talk about this a bit later. So from now on, the term 'decorator' will be understood a... code python> def simple_hello(): print("Hello from simple function!") </code> <code python> def sim... output> We are about to call "simple_hello" Hello from simple function! </code> Now let's create anothe... object representing our ''simple_function()'' and from that moment on it indicates the object returned b
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
20 Resultats, Darrera modificació:
inheritance is a way of building a new class, not from scratch, but by using an already defined repertoi... heritance in Python. You can derive any new class from more than one previously defined class. But mult... tion Order The spectrum of issues possibly coming from multiple inheritance is illustrated by a classica... erclass named A; there are two subclasses derived from A — B and C; and there is also the bottom-most su
3.1 Advanced techniques of creating and serving exceptions
13 Resultats, Darrera modificació:
reason for this is that exceptions are inherited from BaseException, the most general exception class. ... spot an exception. In the case where you get data from an external source (console, file, etc.) you shou... raise RocketNotReadyError('Crew is incomplete') from e __main__.RocketNotReadyError: Crew is incomplet... raise RocketNotReadyError('Crew is incomplete') from e crew = ['John', 'Mary', 'Mike'] print('Final c
2.9 Inheriting properties from built-in classes
9 Resultats, Darrera modificació:
= 2.9 Inheriting properties from built-in classes Python gives you the ability to create a class that inherits properties from any Python built-in class in order to get a new c... f all of the well-known functionalities inherited from its parent or even parents and you can still acce... he genuine method ''%%__setitem__%%'' which comes from the parent class, which does the rest of the job
4.2 Serialization of Python objects using the pickle module
7 Resultats, Darrera modificació:
iver # therefore when you receive a bytes object from an appropriate driver you can deserialize it b_li... python> import pickle def f1(): print('Hello from the jar!') with open('function.pckl', 'wb') as f... pickled successfully, and now we can retrieve it from the file. Run the code in the editor and see wha... r: Can't get attribute 'f1' on <module '__main__' from 'main.py'> </code> Here’s the same example regar
5.1 Metaprogramming
7 Resultats, Darrera modificació:
other programs’ codes. It may sound like an idea from a science fiction story, but the idea was born an... he argument specifies a tuple of the base classes from which the newly created class is inherited; this ... first step is to define a metaclass that derives from the ''type'' type and arms the class with a 'cust... fact that: * the class ''My_Meta'' is derived from ''type''. This makes our class a metaclass; * o
2.7 Encapsulation
6 Resultats, Darrera modificació:
Python, you can change your class implementation from a class that allows simple and direct access to a... f your objects. Let's start with a few analogies from real life: Imagine a washing machine door ( **obj... is a basic countermeasure to protect your account from withdrawals exceeding certain limits or the accou... t('It is good to remember to sanitize the remains from the tank!') self.__level = None </code>
2.8 Composition vs Inheritance - two ways to the same destination
5 Resultats, Darrera modificació:
20231023-022208.png }} Note: the hierarchy grows from top to bottom, like tree roots, not branches. The... n this “Vehicles” structure? All classes derived from Vehicles own properties and methods responsible f... eling, etc. Once you inherit a “mileage” property from the base class, then it is present in all subclas... ite) able to store and use other objects (derived from other classes) where each of the objects implemen
2.1 Python core syntax
4 Resultats, Darrera modificació:
or__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']<... and 2-36. | Base 0 means to interpret the base from the string as an integer literal. | >>> int('0b... own magic method counterparts. Treat it as a list from a universal map, unrelated to any special data ty... means to add seconds; * to subtract an integer from a time interval object means to remove seconds.
2.6 Abstract classes
4 Resultats, Darrera modificació:
y __overriding__ the method declarations received from the class designer. This contract assures you th... When you plan to implement a multiple inheritance from abstract classes, remember that an effective subc... ss should override all abstract methods inherited from its super classes. **Summary**: * Abstract Bas... r concrete classes; * ABC can only be inherited from; * we are forced to override all abstract metho
1.2 Working with class and instance data – instance variables
3 Resultats, Darrera modificació:
ividually for the instance to make it independent from other instances of the same class; - we instant... jects. Instance variables are completely isolated from each other. <code ; output> contents of d1: {'in... e used to count the number of all objects created from the descendant classes (subclasses). We'll achiev
2.3 Extended function argument syntax
3 Resultats, Darrera modificació:
he combiner function. If we remove the asterisks from the function call, then both tuple and dictionary... * positional arguments (a,b) are distinguished from all other positional arguments (args) * the keyword 'c' is distinguished from all other keyworded parameters. Now that we know
2.5 Different faces of Python methods
3 Resultats, Darrera modificació:
must do it consistently in your code. It follows from the convention that //self// literally means a re... tion * To be able to distinguish a class method from an instance method, the programmer signals it wit... ion * To be able to distinguish a static method from a class method or instance method, the programmer
1.1 Classes, Instances, Attributes, Methods — introduction
2 Resultats, Darrera modificació:
as accurately as possible. You can build a class from scratch or, something that is more interesting an... the foremost type that any class can be inherited from; * as a result, if you’re looking for the type
4.1 Shallow and deep copy operations
2 Resultats, Darrera modificació:
.properties = ["112", "997"] print("Hello from __init__()") a_example = Example() b_example = c... o get the following output: <code ; output> Hello from __init__() Memory chunks: 140319166493840 1403191
4.3 Making Python objects persistent using the shelve module
1 Resultats, Darrera modificació: