Data science with Python
Data science with Python
Source: adobestock/84383512
Author:
Amaury Giovanni Méndez Aguirre
INDEX
Introduction................................................................................. 3
What is Python? 5
Starting to program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Commenting on a code...
Variables
Creation of variables..................................... 10
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inheritance
Conclusiones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Bibliographya . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Introduction
INTRODUCTION
5
Hello World!
sum multiplication
print(2 + 3) print(3 * 4)
>> 5 12
print(10 / 3) print(10 // 3)
3.3333333333335 >> 3
print(20 % 6)
>> 2
combine texts
programming in Python
Python programming
["Ciencia","de","Datos"]
Data Science
Figure 1
Source: own
6
Figure 2
Source: own
Starting to program
Comment a code
In Python, just like in other programming languages, you can perform small
or great comments to explain lines of code, leave important information or
any other use that the programmer wishes to leave, and for this, it can be done either a
single line comment or multi-line comments.
7
To comment a single line, simply use the hash symbol #, and to comment
various lines usually use single or double quotes, three times at the beginning
and three times at the end. Let's see how:
“””
Variables
edad = 17
print( age )
>> 17
Note that the equal sign (=) has been used to perform this
Variable:
temporary storage of the number 17 in a created variable It is simply a
with the name age. The number 17 turns out to be a type of memory space
what will be used time-
since in this case it is an integer. In this example, for generally for the soul
show the content of the variable, the print function has been used to have dinner of some kind
date.
) and as a result, the stored number is displayed.
type(age)
>> int
8
Something very important to highlight is that variables can store results.
of different arithmetic operations or objects as shown below:
sum = 5 + 7
print( sum )
12
print( name )
DATA SCIENCE
Figure 3
Source: own
9
Creation of variables
ancho = 15
Altura = 20
_radio = 3.5
It can contain other letters, numbers, and the underscore later, for example:
primer_nombre = “Giovanni”
_horas_dia2 = 4
Variable names are case sensitive, which means that the variable
height will be different from the variable Height or from the variable HEIGHT
Visit page
https://www.w3schools.com/python/python_ref_keywords.asp
10
Exercises
1. y = x2+4x+10 where x = 5
3. y = 2x3-4x+10 -6 * 7 donde x = 35
x=5
y = x**2 + 4*x + 10
print("y =", y)
y = 55
11
Structured programming vs Object-oriented programming
edad = 20
Figure 4
Source: own
In this example, a feature has been defined in the form of a variable with the word
age, and it has been assigned a numerical value of integer type 20. The result of the program
it will be the message 'end of the program' since the imposed condition of a lower value
Number 19 is not fulfilled, but we will study this in more depth later.
now consider that a structured or sequential program simply takes instructions
actions hierarchically and executes them one by one.
12
In the following example, analyze a problem where father and son each have a
car and it is desired to describe its characteristics as shown below:
auto_padre_color = “rojo”
auto_hijo_modelo = 2020
print (father_auto_model)
Figure 5
Source: own
13
In this example, Python will show us an error in which it tells us that the variable
auto_padre_modelo has not been defined, and it's right!, since although the variable has
It has been defined for the child car, but not for the parent car, and vice versa with the character.
Characteristic of color. Can you imagine how many variables we would have to create to describe
the characteristics of each car, not just for this example, but for example, for each
new car that enters our program? And if at some point a definition were made of a
new feature for cars, like a new navigation system, how many
What new variables would we have to create? Well, this is where object-oriented programming
objects make sense as they save us from creating new variables through the
ability to create new objects from a template known as
of Class. In fact, by creating variables where we define names, we are creating new
your text-type objects (str) and they are inheriting all their attributes and methods.
Let's look at an example:
print(nombres.upper(), apellidos.upper())
Figure 6
Source: own
Note that when creating the variables names and surnames, both have the ability to
use the .upper() method that transforms the text into uppercase
14
In code, a 'Class' is created as follows (it is very important that when you type-
Take the following example, spaces should be respected, as it is a characteristic of Python
called indentations
self.model = model
self.color = color
def see_model(self):
print(self.model)
def check_color(self):
print(self.color)
son.show_model()
>> 2022
15
Figure 7
Source: own
16
Inheritance
In programming, you can create object classes that can inherit both the attributes
but like the methods so you don't have to redefine any of these. In the
In the next example, you will see the creation of a machine class and from this, the creation
of other classes
Figure 8
Source: own
17
In this example, some are highlighted The variables meet conditions for
things: to be declared or created and can count-
ner any type of existing data in the
1. The reserved word pass is used lenguaje Python. Estas reglas son:
to leave part of the code undefined,
as it happens in the __init__ method a.They can start with a letter (a-z)
(self). (A-Z)
2.When inheriting, the name of the cla- b.They can start with an underscore.
from which it is going to be inherited, like ejemplo:_nombre
it happens in the case of the classclass
Computer (Machine) where it is- c.They are case sensitive, which indicates that
we are programming the classclass apple is different from Manzanao
Computer, all the attributes and APPLE and all its possible com-
methods that the class has class Ma- combinations of uppercase and lowercase
the class Computer has- the
read the method turn on of Machine
and that's why when creating the object pc_portatil, d. The words re- cannot be used
this can make use of that method reserved in Python as variables
through the instruction pc_porta-
turn_on()
Recommended reading
Conclusions
18
BIBLIOGRAPHY