Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.6 Abstract classes
- esn’t mean that there are no controls to impose a set of functionalities or an order in a class hierar... r__ and a __programmer__: * the class designer sets requirements regarding methods that must be imp... upon your abstract class, will be equipped with a set of concrete methods imposed by the abstract clas... polymorphic, so all subclasses have to deliver a set of their own method implementations in order to
- 2.1 Python core syntax
- ng operators, or to get a number of elements in a sequence or dictionary. We are able to add two or m... sents a person; each instance of the class owns a set of attributes describing a person: age, salary, ... tion: <code python>class Person: def __init__(self, weight, age, salary): self.weight = weight self.age = age self.salary = sa
- 2.7 Encapsulation
- ance is washing it ( **processing** ). You have a set of controls ( **methods** ) that allow you to manage your laundry, or even see it (many wash machines are equipped with a trans... t** access it directly and without some checks or security. This is a basic countermeasure to protect ... * ) exceeding the total tank capacity, or request setting the liquid level to a negative value. Pytho
- 1.1 Classes, Instances, Attributes, Methods — introduction
- unctions, modules, lists, etc.). In the very last section of this module, you'll see that even classes are instances. Why is everything in Python organiz... ism adds classes with a minimum of new syntax and semantics: <code python> class Duck: def __init__(self, height, weight, sex): self.height = he
- 2.8 Composition vs Inheritance - two ways to the same destination
- ts. The objects used in the composition deliver a set of desired traits (properties and/or methods) so... program runtime. Let's try to write some code to see how composition works. Look at the simple code ... pane. <code python> class Car: def __init__(self, engine): self.engine = engine class GasEngine: def __init__(self, horse_power):
- 2.9 Inheriting properties from built-in classes
- hods by delivering your own modifications for the selected methods. In the following example, we’ll c... an object? Imagine that you need to collect the serial numbers of sold tickets. Sound reasonable eno... aise ValueError('Not an integer type') def __setitem__(self, index, value): IntegerList.check_value_type(value) list.__setitem__(self
- 1.2 Working with class and instance data – instance variables
- removed at any time. Each object carries its own set of variables – they don't interfere with one ano... elow. <code python> class Demo: def __init__(self, value): self.instance_var = value d1 = Demo(100) d2 = Demo(200) print("d1's instance var... stance_var variable for the instance. The keyword self is used to indicate that this variable is creat
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- variants mean different things in Python) Can you see the diamond there? {{ :info:cursos:pue:python-pc... t of the code? <code python>class A: def info(self): print('Class A') class B(A): def info(self): print('Class B') class C(A): def info(self): print('Class C') class D(B, C):
- 2.5 Different faces of Python methods
- tance 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 cours... e. <code python> class Example: def __init__(self, value): self.__internal = value def get_internal(self): return self.__interna
- 4.2 Serialization of Python objects using the pickle module
- = 4.2 Serialization of Python objects using the pickle module In this section, you will learn how to persist Python object... ng to do way which is not suitable for persisting sets of different types of objects or nested structures. In Python, object **serialization** is the process of converting an obje
- 2.4 Decorators
- ook at the following syntactic sugar: As you can see, the definition of the ''simple_hello()'' functi... ou to pass the packing material in the argument. See the code presented in the right pane. <code pyt... abcd = subject_matter_function() </code> the call sequence will look like the following: * the outer... estamp (in a form like year-month-day hour:minute:seconds, eg. 2019-11-05 08:33:22) * Create a few o
- 5.1 Metaprogramming
- ()'' function. Run the code in the right pane to see the ''type()'' function in action. <code python... ss '__main__.Dog'> <class 'type'> </code> We can see that objects in Python are defined by their inhe... sented in the right pane. <code python> def bark(self): print('Woof, woof') class Animal: def feed(self): print('It is feeding time!') Dog = t
- 4.1 Shallow and deep copy operations
- ess. Run the code presented in the right pane to see how the strings are located in the memory. <cod... ist'' object; * modify the original object; * see the contents of both objects. Pay attention to ... the objects found in the original; * as you can see, a shallow copy is only one level deep. The copy... PU – just a copy of a reference to 'a_list'. The second approach is a shallow copy. This is slower th
- 3.1 Advanced techniques of creating and serving exceptions
- = 3.1 Advanced techniques of creating and serving exceptions In this module, we'll talk about Python e... ram will be **forcibly terminated**, and you will see an error message sent to the console by Python; * otherwise, if the exception is taken care of and... ered the exception, respectively. Could be None. See the output of this snippet to analyze the attrib
- 4.3 Making Python objects persistent using the shelve module
- hon objects persistent using the shelve module == Serialization of Python objects using the shelve mod... le As you remember, the pickle module is used for serializing objects as a single byte stream. Both serializing and deserializing parties must abide by th... l the elements placed into a file or database, or sent via a network. There is another handy module,