01 - 02.1.1 Fundamentos de Programación en Python - Numeros y Operadores
01 - 02.1.1 Fundamentos de Programación en Python - Numeros y Operadores
Unidad 1 – Fundamentos de
programación en Python
LOGRO DE APRENDIZAJE
TEMA 1 TEMA 2
Introducción y Tipo Operadores y
de Datos expresiones
TEMARIO
TEMA 1
Introducción y Tipo de Datos
1.1 Introducción y Tipos de Datos
Nombre de variables
Una variable puede tener nombres cortos como X e Y, o tener nombres mas descriptivos como Edad,
Nombre, Volumen_Total.
Reglas para las variables de Python:
➢ Una variable debe iniciar con una letra o una raya abajo ( _ underscore character)
➢ Una variable no puede iniciar con numero
➢ Una variable puede contener solo caracteres alfa numéricos o raya abajo (A-z, 0-9, and _ )
➢ Los nombres de las variables son sensibles a las mayúsculas (p.e. edad, Edad, EDAD son tres variables
diferentes)
Declaración de variables
Python como muchos lenguajes, declara la variable con el primer valor asignado a este. NO REQUIERE UN
COMANDO
➢ x=5
➢ y = "Hello, World!“
Comentarios
Python con el propósito de documentar sus códigos de línea, permite comentarlas mediante el carácter # al inicio de la
línea:
➢ #Este es un comentario
print("Hola, mundo!")
➢ print("Hola, mundo!") #Este es un comentario
Data type
Data type
Asignación de variables
Example Data Type
x = "Hello World" str
x = 20 int
x = 20.5 float
x = 1j complex
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = {"name" : "John", "age" : 36} dict
x = {"apple", "banana", "cherry"} set
x = frozenset({"apple", "banana", "cherry"}) frozenset
x = True bool
x = b"Hello" bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
1.1 Introducción y Tipos de Datos
Data type
Para asignar a una variable un tipo de dato especifico, se deben utilizar las siguientes funciones:
Example Data Type
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = list(("apple", "banana", "cherry")) list
x = tuple(["apple", "banana", "cherry“]) tuple
x = range(6) range
x = dict(name="John", age=36) dict
x = set(("apple", "banana", "cherry")) set
x = frozenset(("apple", "banana", "cherry")) frozenset
x = bool(5) bool
x = bytes(5) bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
1.1 Introducción y Tipos de Datos
Numbers (números)
Enteros – Int, or integer, es un numero entero, positivo o Complejos – Que se escriben como un j como
negativo, sin decimales, de longitud indefinida parte imaginaria
x=1 x = 3 + 5j
y = 35656222554887711 y = 8j
z = -3255522 z = 10 -3j
print( type(x) ) print( type(x) )
print( type(y) ) print( type(y) )
print( type(z) ) print( type(z) )
TEMA 2
Operadores y expresiones
1.2 Operadores y expresiones
Operadores de asignación
Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
1.2 Operadores y expresiones
Operadores de comparación
Operadores lógicos
Operator Description Example
and Returns True if both statements are true x < 5 and x < 10
Operadores de identidad
Los operadores de identidad se usan para comparar los objetos, no si son iguales, sino si en realidad son
el mismo objeto, con la misma ubicación de memoria:
Operator Description Example
is Returns True if both variables are the same object x is y
is not Returns True if both variables are not the same object x is not y
1.2 Operadores y expresiones
Operadores de miembros
Los operadores de membresía se utilizan para probar si una secuencia se presenta en un objeto:
Operadores Bitwise
Los operadores bit a bit se usan para comparar números (binarios):
Operato Name Description
r
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the
rightmost bits fall off
INSERTAR NOMBRE DE ACTIVIDAD
ACTIVIDAD
Debe resolver los ejercicios señalados por el
profesor que se encuentran en el documento:
03
04
BIBLIOGRAFÍA
RAMALHO, LUCIANO (2015) Fluent Python: Clear, Concise, and Effective Programming
(inglés) 1st Edición. California: O’Reilly.
Material producido por la
Universidad Peruana de
Ciencias Aplicadas
Continúa con las actividades Autor:
propuestas Norman Reyes Morales
COPYRIGHT © UPC
2020 – Todos los
derechos reservados