Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.1 Python core syntax
- e strings together, which results in the strings’ concatenation; we are able to add integers and we kno... or double underscores, as it’s a shorter and more convenient phrase). Dunders indicate that such method... n core syntax rules. The '+' operator is in fact converted to the __add__() method and the len() function is converted to the __len__() method. These methods must
- 2.8 Composition vs Inheritance - two ways to the same destination
- ar we've been using and following the inheritance concept when modeling our classes to represent real-life issues. Inheritance is a great concept, one of the most important foundations of obj... cle” object, is easily achieved. The inheritance concept is a powerful one, but you should remember th... programming. Inheritance is not the only way of constructing adaptable objects. You can achieve simil
- 4.1 Shallow and deep copy operations
- s an integer which is guaranteed to be unique and constant for this object during its lifetime. Two obj... ame. Run the code presented in the right pane to confirm our speculations: <code python> a_string = '1... ject; * modify the original object; * see the contents of both objects. Pay attention to the code ... h ''a_list'' is a compound object (an object that contains other objects, like lists, dictionaries, or
- 3.1 Advanced techniques of creating and serving exceptions
- **, and you will see an error message sent to the console by Python; * otherwise, if the exception is... nded program can be resumed and its execution can continue. Python provides effective tools that allow... te your own specific exception classes – the only constraint is: you have to subclass BaseException or ... o a nasty thing...') </code> Whenever you try to convert letter 'a' to an integer value, you'll spot a
- 1.2 Working with class and instance data – instance variables
- The word instance suggests that they are closely connected to the objects (which are class instances),... oment of an object's life. Moreover, it lists the contents of each object, using the built-in __dict__ ... er_var = 'another variable in the object' print('contents of d1:', d1.__dict__) print('contents of d2:', d2.__dict__) </code> This example shows that modi
- 5.1 Metaprogramming
- r example of metaprogramming is the **metaclass** concept, which is one of the most advanced concepts presented in this course. Tim Peters, the Python gur... redirect class instantiations to dedicated logic, contained in metaclasses. Metaclasses are applied whe... ode> These observations lead us to the following conclusions: * metaclasses are used to create clas
- 2.6 Abstract classes
- = 2.6 Abstract classes Python is considered to be a very flexible programming language, but that doesn’t mean that there are no controls to impose a set of functionalities or an ord... n abstract class? An **abstract class** should be considered a blueprint for other classes, a kind of contract between a __class designer__ and a __programm
- 4.2 Serialization of Python objects using the pickle module
- aced with the 'pickled' adjective. Have you ever considered saving the output of your data processing ... ython, object **serialization** is the process of converting an object structure into a stream of bytes... or to transmit it via a network. This byte stream contains all the information necessary to reconstruct the object in another Python script. This reverse p
- 2.7 Encapsulation
- psulation Encapsulation is one of the fundamental concepts in object-oriented programming (amongst inhe... ted:20231023-004942.png }} Python introduces the concept of **properties** that act like proxies to encapsulated attributes. This concept has some interesting features: * the code ... talking" to the real attributes or to the methods controlling access to the attributes; * in Python,
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- llar of OOP Inheritance is one of the fundamental concepts of object oriented programming, and expresse... ecialized (or more specific) than its superclass. Conversely, each superclass is more general (more abs... the current class. If it is not found, the search continues into the direct parent classes in depth-fir... for it in the class hierarchy; * **class D** is constructed in this order: * the definition of **
- 2.5 Different faces of Python methods
- you can use a different word, but you must do it consistently in your code. It follows from the convention that //self// literally means a reference to the... As a result, our perception of the Python class concept is extended by two types of specialized metho... sibilities, here are the two most popular: - we control access to class variables, e.g., to a class v
- 2.4 Decorators
- print two other lines? Where is the simplicity or convenience in this approach? Well … we could say … ... ction! </code> == Decorators should be universal Consider a function that accepts arguments and should... situation, we can use the *args and %%**%%kwargs concepts. We can also employ a closure technique to p... ends it execution, the inner_decorator takes over control, and after it finishes its execution, the out
- 2.9 Inheriting properties from built-in classes
- fic type (integers in the ticketing example), and control over the types of elements is given to the me... problem, we focus on the problem and not on type control. Look at the code presented in the editor pa... lidator to ensure that our banking app dictionary contains only validated IBANs (keys) and info about t... count_Number]]. An IBAN-compliant account number consists of: * a two-letter country code taken fro
- 1.1 Classes, Instances, Attributes, Methods — introduction
- * it is an independent instance of class, and it contains and aggregates some specific and valuable da... instance. The class is something virtual, it can contain lots of different details, and there is alway... e code above, we have defined a class named Duck, consisting of some functionalities and attributes. A... two major kinds of class traits: * variables, containing information about the class itself or a cl
- 4.3 Making Python objects persistent using the shelve module
- ou access Python dictionaries. This could be more convenient for you when you’re serializing many objec... ile to demonstrate direct access to the elements (contrary to the sequential access to items when we us... ernal utilities, because your shelve may become inconsistent, resulting in read/write errors. The use