Listas y fecha en Python

26

Click here to load reader

description

Power for the class of Python

Transcript of Listas y fecha en Python

Page 1: Listas y fecha en Python

LISTASLISTASColecciones

Page 2: Listas y fecha en Python

LISTAS

• Una LISTA es un tipo de dato de Python que permite almacenar COLECCIONES de elementos.

• Las LISTAS son:

• Mutables

• Dinámicas

Page 3: Listas y fecha en Python

LISTAS

• Definición: identificador=[lista de elementos]

• Tipo de dato de los elementos:

• int, float, boolean, list, …

Page 4: Listas y fecha en Python

CONSULTAS

• len(lista)

• type(lista)

Page 5: Listas y fecha en Python

LISTAS• Acceso a los elementos: identificador[posición]

• En una lista encontramos:

• Elementos: lista[posición]

• Posición: 0 .. len(lista) - 1

Page 6: Listas y fecha en Python

LISTAS

• Acceso a los elementos:

Page 7: Listas y fecha en Python

RECORRIENDO LISTAS

• MÓDULO: UsoDeListas.py

Page 8: Listas y fecha en Python

RECORRIENDO LISTAS

• Uso de sentencia for in:

Page 9: Listas y fecha en Python

RECORRIENDO LISTAS

• Uso de sentencia for range:

• +

Page 10: Listas y fecha en Python

RECORRIENDO LISTAS

• Determinar el mayor valor dentro de una lista:

Page 11: Listas y fecha en Python

OPERACIONES LISTAS

Page 12: Listas y fecha en Python

OPERACIONES LISTAS

• Agregar un elemento:

• append

• Agregar un elemento:

• extend

Page 13: Listas y fecha en Python

OPERACIONES LISTAS

• Insertar un elemento:

• insert

Page 14: Listas y fecha en Python

OPERACIONES LISTAS

• Eliminar un elemento: del(lista[i]), lista.remove(elem)

Page 15: Listas y fecha en Python

CONSULTAS LISTAS• Determinar índice: lista.index(elem)

• Determinar existencia: elemento in lista

Page 16: Listas y fecha en Python

ELEMENTOS REPETIDOS

• Veces que aparece un elemento: lista.count(elem)

Page 17: Listas y fecha en Python

LISTA: ORDENAR - INVERTIR

• Ordenar: lista.sort()

• Invertir: lista.reverse()

Page 18: Listas y fecha en Python

LISTAS: OPERACIONES

• +

Page 19: Listas y fecha en Python

LISTAS: OPERACIONES

• *

Page 20: Listas y fecha en Python

LISTAS COMO CONTADORES

• Cada uno de sus elementos, cumple la función de contador.

Page 21: Listas y fecha en Python

FECHA -HORAFECHA -HORAOBTENER LA FECHA DEL SISTEMA

Page 22: Listas y fecha en Python

FECHA DEL SISTEMA

• import datetime

• Diferentes formas de instanciar un objeto FECHA

Page 23: Listas y fecha en Python

FECHA DEL SISTEMA

• import datetime

Page 24: Listas y fecha en Python

CONVERSIONES FECHA

• import datetime

• Fecha a String: strftime(formato String)

Page 25: Listas y fecha en Python

CONVERSIONES FECHA

• import datetime

• String a Fecha: strptime(String, )

Page 26: Listas y fecha en Python

OTRAS FUNCIONES DE FECHA

• Ver otras funciones de fecha:

• timedelta(??)

• isoweekday()