Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Python classes attributes, Appunti di Patente Europea del Computer (ECDL)

Notes on python classes attributes and methods

Tipologia: Appunti

2019/2020

Caricato il 27/01/2020

Pazzoz99
Pazzoz99 🇮🇹

11 documenti

1 / 3

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
Classes, Istances, methods
A Class is like an object constructor, or a "blueprint" for creating objects.
Different classes have different methods, therefore according to which class an object belongs to
we can use different methods.
While the class is the blueprint, an instance is a copy of the class
with actual values, literally an object belonging to a specific class.
To create a class, use the keyword ‘class’. Then in the body you define the attributes of the
objects belonging to the class and the different methods that can be applied to the class.
Then you can use the class to create a new object.
All classes create objects, and all objects contain characteristics called
attributes.
Use the __init__() method to initialize (e.g., specify) an object’s
initial attributes by giving them their default value (or state). This
method must have at least one argument as well as
the self variable, which refers to the object itself.
Remember: the class is just for defining the Dog, not actually
creating instances of individual dogs with specific names and
ages; we’ll get to that shortly.
While instance attributes are specific to each object, class attributes are the same for all
instances—which in this case is all dogs.
Instantiating is a fancy term for creating a new, unique instance
of a class.
pf3

Anteprima parziale del testo

Scarica Python classes attributes e più Appunti in PDF di Patente Europea del Computer (ECDL) solo su Docsity!

Classes, Istances, methods

A Class is like an object constructor, or a "blueprint" for creating objects. Different classes have different methods, therefore according to which class an object belongs to we can use different methods. While the class is the blueprint, an instance is a copy of the class with actual values, literally an object belonging to a specific class.  To create a class, use the keyword ‘class’. Then in the body you define the attributes of the objects belonging to the class and the different methods that can be applied to the class.  Then you can use the class to create a new object.  All classes create objects, and all objects contain characteristics called attributes.  Use the init() method to initialize (e.g., specify) an object’s initial attributes by giving them their default value (or state). This method must have at least one argument as well as the self variable, which refers to the object itself. Remember: the class is just for defining the Dog, not actually creating instances of individual dogs with specific names and ages; we’ll get to that shortly.  While instance attributes are specific to each object, class attributes are the same for all instances—which in this case is all dogs.  Instantiating is a fancy term for creating a new, unique instance of a class.

 Instance methods are defined inside a class and are used to get the contents of an instance. They can also be used to perform operations with the attributes of our objects. Like the init method, the first argument is always self

Inheritance

Inheritance is the process by which one class takes on the attributes and methods of another. Newly formed classes are called child classes , and the classes that child classes are derived from are called parent classes. It’s important to note that child classes override or extend the functionality (e.g., attributes and behaviors) of parent classes. The most basic type of class is an object, which generally all other classes inherit as their parent. When you define a new class, Python 3 it implicitly uses object as the parent class.