“Porte negativo en la lista de Python” Código de respuesta

Porte negativo en la lista de Python

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[-4:-1])
Programmer of empires

Porte de lista negativa

# Creating a List
List = ['S','O','F','T','H','U',
        'N','T','.','N','E','T']
print("Initial List: ")
print(List)

# Print elements from beginning
# to a pre-defined point using Slice
Sliced_List = List[:-6]
print("\nElements sliced till 6th element from last: ")
print(Sliced_List)
 
# Print elements of a range
# using negative index List slicing
Sliced_List = List[-6:-1]
print("\nElements sliced from index -6 to -1")
print(Sliced_List)
 
# Printing elements in reverse
# using Slice operation
Sliced_List = List[::-1]
print("\nPrinting List in reverse: ")
print(Sliced_List)
Outrageous Ostrich

Respuestas similares a “Porte negativo en la lista de Python”

Preguntas similares a “Porte negativo en la lista de Python”

Más respuestas relacionadas con “Porte negativo en la lista de Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código