-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_read.py
53 lines (41 loc) · 1.15 KB
/
2_read.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Listas FTW!
foods = ["Hamburguesa", "Tacos", "Pasta", "Lasagna"]
print(foods)
# Accesar a elementos
print(foods[0]) # Hamburguesa
print(foods[2]) # Pasta
# Agregar elementos
foods.append("Sushi")
foods.append("Ensalada")
print(foods)
# Eliminar elementos
foods.remove("Ensalada")
print(foods)
# Revisar si un elemento está presente
"Ensalada" in foods # => False
"Sushi" in foods # => True
# Accesar a un grupo de elementos
print(foods[1:3])
print(foods[3:])
# Que pasa si accedo a un elemento no existente?
# print(foods[12]) ! [IndexError: list index out of range]
# Como puedo evitar el error?
foods.get(12)
# Tambien se puede borrar un grupo de elementos en la lista
# del(foods[3:])
# print(foods)
# Listas de lo que sea
item_description = ["Spider-Man", 1982, 1099.99]
print(item_description)
appearances = [True, True, None, False]
print(appearances)
# ! Pero es menos comun ¯\_(ツ)_/¯
# Funciones relacionadas con Listas
print("Hay", len(foods), "comidas en la lista")
print(foods)
for number in range(10):
if number % 2 == 0:
print(number)
foods = ["Burger", "Spaghetti", "Lasagna", "Tacos"]
for food in foods:
print("Shrimp", food)