Codigo en Python
Codigo en Python
py
variables.py
name = "Fast"
print(100+20)
print(name)
name1=None
print(name1)
x=100
# case sensitive
book="Digital Fortress"
Book="Digital Fortress"
y=200
Boook="I Robot"
print(y)
print(Boook)
print(x, Book)
PI = 3.1416
MY_NAME = "Roberto"
strings.py
lists.py
r= list(range(1, 100))
print(r)
print(dir(colors))
print(len(demo_list))
print(colors[-1])
print(colors[0])
print('violet' in colors)
print('red' in colors)
print(colors)
colors[1]= 'yellow'
print(colors)
colors.append('violet')
print(colors)
#colors2.append('violet')
#colors2.append(('violet','yellow'))
#colors2.append(['violet','yellow'])
#colors2.extend(('violet','yellow'))
colors2.extend(['violet','yellow','brown'])
print(colors2)
colors2.insert(len(colors2), 'Blanco')
print(colors2)
colors2.insert(-1, 'Negro')
print(colors2)
colors2.remove('red')
print(colors2)
colors2.pop(1) #Elimina según el indice
print(colors2)
print(colors3)
colors3.clear()
print(colors3)
print(colors4)
colors4.sort() #Lo ordena en forma alfabetica
print(colors4)
colors4.sort(reverse=True) #Ordena en forma inversa
print(colors4)
print(colors4.index('MARRÓN')) #Obtenemos el indice
print(colors4)
print(colors5)
print(colors5.count('ROJO'))
tuples.py
x = (1, 2 ,3)
print(type(x))
months = ('January', 'February', 'March')
print(months)
y = tuple((1, 2, 3))
print(y)
#print(dir(tuple))
y = (1, 2 ,3, 4, 5)
print(y[1])
z = (1, 2 ,3)
del z
# print(z) Muestra error porque ya no existe, fue eliminado
locations = {
(35.12312, 39.000):"Tokyo",
(35.12313, 38.000):"New York"
}
print(locations)
dictionary.py
product = {
"name": "book",
"quantity": 3,
"price": 4.99
}
print(type(product))
print(dir(product))
print(product.keys())
print(product.items())
product2 = {
"name": "book",
"quantity": 3,
"price": 4.99
}
del product2
#print(product2) No puedo eliminarlo porque ya esta eliminado
product3 = {
"name": "book",
"quantity": 3,
"price": 4.99
}
product3.clear()
print(product3)
product4 = [
{"name": 'book', "quantity": 3},
{"price": 4.99, "name": 'laptop'}
]
print(product4)
set.py
colors = {'Red', 'Green', 'Blue'} #No tiene indice el tipo de dato set
print(colors)
print('Red' in colors)
colors.add('Violet')
print(colors)
colors.remove('Red')
print(colors)
datatype.py
# Strings
print("Hello world")
print('Hello World')
print('''Hello World''')
print("""Hello World""")
type("Hello World")
print(type("Hello World"))
print("Bye"+"World")
# Integer
print(10)
# Float
print(30.5)
# Boolean
print(True)
print(False)
# List =>Si se puede cambiar los datos
[20, 30, 40, 50]
['Hello','Bye',"Adiós"]
[]
print([10,"Hello",True,10.1])
#Tuples =>No se puede cambiar los datos
(10, 20,30,40)
print(type((10, 20,30,40)))
()
#Dictionary =>Esta definido por clave y valor
{
"Name": "Marlon",
"Lastname": "Aguilar",
"Nickname":"Tigre"
}
print(type({
"Name": "Marlon",
"Lastname": "Aguilar",
"Nickname":"Tigre"
})
)
#Tipo de dato que no tiene nada
None
print(type(None))
functions.py
# print("Marlon Aguilar")
# dir(x)
# type(12)
def hello():
print("Hello World")
def hello2(name):
print("Hello World " + name)
# print(add(10, 30))
print(add(10, 30))
print(len("hello")) #funcion preconstruida
condicionals.py
a = 20
if a < 30:
print("a is less than 30")
x = 20
if x < 30:
print("x is less than 30")
else:
print("x is greater than 20")
y = 40
if y == 20:
print("y is less than 30")
elif y==30:
print("y is greater than 20")
else:
print("y is is")
name="Jhon"
lastname="Carter"
if name == "Jhon":
if lastname == "Carter":
print("You are Jhon Carter")
else:
print("You are not Jhon Carter")
else:
print("You are not Jhon")
loops.py
#print(foods[0])
range(1, 8)
numbers.py
print(16/6)
print(16//6)
print(16%6)
age = input("Inserte tu edad: ")
print(age)
print(type(age))
print(type(int(age)))
print(type(float(age)))
mymath.py
modules.py
print(date.today())
modules1.py
import mymath
modules2.py
substract(1, 2)
add(1, 2)
modules3.py