Cerca

Heus ací els resultats de la cerca.

2.9 Inheriting properties from built-in classes
33 Resultats, Darrera modificació:
ion of our own list class, which will only accept elements of the integer type. But, wait – why might ... implementation and will also validate the type of elements that are about to be placed onto it. Such ... be used in an application that requires the list elements to be of a specific type (integers in the ticketing example), and control over the types of elements is given to the mechanisms of the new class
2.6 Abstract classes
9 Resultats, Darrera modificació:
nized as an abstract one, because it inherits all elements of its super class, which is abstract, and ... def scan_document(self): print("El document ha estat escanejat") def get_scanner... f): fax = "" if self.fax_machine == False else ", Fax" print( "màxima resolució scanne... r) ) def print_document(self): print("El document ha estat imprés") def get_printer_st
2.8 Composition vs Inheritance - two ways to the same destination
9 Resultats, Darrera modificació:
15), off-road tires (size: 18) * two engines: electric engine, petrol engine * instantiate two o... s: * the first one is a city car, built of an electric engine and city tires * the second one ... s cityTires = Tires(15) offRoadTires = Tires(18) electricEngine = Engine("Electric") petrolEngine = Engine("Petrol") car1 = Car(electricEngine, cityTire
2.1 Python core syntax
8 Resultats, Darrera modificació:
ols representing operators, or to get a number of elements in a sequence or dictionary. We are able t... se the same function ''len()'' to get a number of elements of a tuple, list, dictionary, or characters... xion – isinstance(), issubclass() and a few more elements. Python allows us to employ operators when... tion. If you’re developing an application for an elevator, then you should remember that every elevat
2.5 Different faces of Python methods
8 Resultats, Darrera modificació:
len(iban) == 20: return True else: return False </code> *... len(iban) == 20: return True else: return False account_numbers = ['8' * 20, '7' * 4, '2222'] for element in account_numbers: if Bank_Account.validate(element): print('We can use', element, ' to
2.7 Encapsulation
8 Resultats, Darrera modificació:
self.__level = amount else: raise TankError('Too much liquid in the tank') elif amount < 0: raise TankError('Not po... self.__level = amount else: raise TankError('Too much liquid in the tank') elif amount < 0: raise TankError('Not po
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
5 Resultats, Darrera modificació:
refer to the objects using the arbitrary variable element. <code python> class Device: def turn_o... tableRadio = PortableRadio() tvset = TvSet() for element in (device, radio, portableRadio, tvset): element.turn_on() </code> <code ; output> The device... ): print("A fire has been started!") for element in Wax(), Cheese(), Wood(): try:
5.1 Metaprogramming
5 Resultats, Darrera modificació:
)'' function with one argument: <code python> for element in (1, 'a', True): print(element, 'is', element.__class__, type(element)) </code> <code ; output> 1 is <class 'int'> <class 'int'> a is <class '
1.1 Classes, Instances, Attributes, Methods — introduction
3 Resultats, Darrera modificació:
tion of a class that occupies memory and has data elements. This is what 'self' refers to when we deal... r = number def turn_on(self): print("el mòbil %s està engegat" % (self.number) ) def turn_off(self): print("el mòbil %s està apagat" % (self.number) )
1.2 Working with class and instance data – instance variables
2 Resultats, Darrera modificació:
ry.species == 'duck': poultry.quack() elif poultry.species == 'chicken': poultry.c... :%s %s" % (Pomes.total_w,Pomes.total_i) ) else: self.weight = random.uniform(0.2,0
4.1 Shallow and deep copy operations
2 Resultats, Darrera modificació:
ng use of variables. As variables are fundamental elements that allow us to cope with objects, let's t... copying a large compound object (a million three-element tuples). <code python> import copy import t
4.3 Making Python objects persistent using the shelve module
2 Resultats, Darrera modificació:
lizing parties must abide by the order of all the elements placed into a file or database, or sent via... e shelve file to demonstrate direct access to the elements (contrary to the sequential access to items
3.1 Advanced techniques of creating and serving exceptions
1 Resultats, Darrera modificació:
ept'' clause will try to handle the problem in an elegant way. Let's look at typical try ... except s