How object and class attributes work?

Santiago Yanguas
4 min readOct 8, 2019

--

Before of we look objects, class and attributes, We come to inquire in the history.

https://realpython.com/python3-object-oriented-programming/

All the concepts that we are saying about class methods atributes, belong to the OOP(Object Oriented Programming), it was maked by Alan kay in the 70s who had studied biology, which allowed parallelism between cell and programming.

I’m going to do is exemplify how a video of White balloon vs bacteria with music from linkin park in the background has to do with programming.

What is a class?

It’s a group of things that have something in common, in the video you could watch one class, it can be called cell. There are cell how the white balloon vs bacteria.

Python3 Class

What’s a class attribute?

A attribute in programming is a variable, it allow at the class differenciate of others, a attribute is something that allows us to differentiate ourselves, in the video for example: the size, if is heterotrophic or autotrophic, color, etc..

Python3 Attributes

What is a method?

A method is how a verb, it speaking in simples word, because the methods always perform a function in the example of the video is: Move, attack, defend, eat.

Python3 Methods

What’s an instance attribute?

A instance is one object or in the example of the video the cell, it maked already the which, we can access for modify yours features.

Making Cells
Python3 Object

What are all the ways to create them and what is the Pythonic way of doing it?

If, We want make a class in python is very matter know about the before concepts more the concept constructor and destructor is similar to humans and cells in simples words is born and die.

Python3 Make One Class

What are the differences between class and instance attributes?

I going to answer through a example: You are in a lab

Class = Chromosomes of a bacterium with the we will can make it.

Instance attributes: Imagine that, We are inside of a laboratory and the bosses ask us a researching about the behavior of the White balloon vs Virus, we have the template for make our several cells, it can be Bacteria’s or White balloon, so we make our cell called object based in the template called class.

Other example with animals

Code

Class Cells:

MyMethod __init__():

print(“Hello cell”)

Object above

Cell1 = Cells()

What are the advantages and drawbacks of each of them?

The advantages it can be best reusability of the code the which compress that we have make a lot of variables through the objects, the problem is with the class because we can modify.

Note: Is very matter we have clear the concept of encapsulation for understand how ensure our classe’s

Encapsulation

How does Python deal with the object and class attributes using the __dict__?

Finally some tip matter for our class is how watch the attributes of instance is that each class the can watch through the dictionary the which contain the different behavior what will you have the class.

Methaphore

--

--