Después de de nuestra extensa búsqueda de datos pudimos resolver esta incógnita que suelen tener muchos usuarios. Te brindamos la respuesta y esperamos resultarte de mucha apoyo.
Ejemplo 1: Python cómo dividir listas
# Basic syntax:
your_list[start:stop:step]# Note, Python is 0-indexed# Note, start is inclusive but stop is exclusive# Note, if you leave start blank, it defaults to 0. If you leave stop# blank, it defaults to the length of the list. If you leave step# blank, it defaults to 1.# Note, a negative start/stop refers to the index starting from the end# of the list. Negative step returns list elements from right to left # Example usage:
your_list =[0,1,2,3,4,5]
your_list[0:5:1]-->[0,1,2,3,4]# This illustrates how stop is not inclusive# Example usage 2:
your_list =[0,1,2,3,4,5]
your_list[::2]# Return list items for even indices-->[0,2,4]# Example usage 3:
your_list =[0,1,2,3,4,5]
your_list[1::2]# Return list items for odd indices-->[1,3,5]# Example usage 4:
your_list =[0,1,2,3,4,5]
your_list[4:-6:-1]# Return list items from 4th element from the left to # the 6th element from the right going from right to left-->[4,3,2,1]# Note, from the right, lists are 1-indexed, not 0-indexed
Ejemplo 2: cortar en una lista de Python
a =[1,2,3,4,5]
a[m:n]# elements grrater than equal to m and less than n
a[1:3]=[2,3]
valoraciones y comentarios
Eres capaz de añadir valor a nuestra información cooperando tu experiencia en los informes.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)