“Lista de fatiamento” Respostas de código

Lista de python fatia

thislist = ["1.apple", "2.banana", "3.cherry", "4.orange", "5.kiwi", "6.melon", "7.mango"]

# thislist[starting index(including) : end index(not including):step]

print(thislist[:]) #Output: ['1.apple', '2.banana', '3.cherry', '4.orange', '5.kiwi', '6.melon', '7.mango']
print(thislist[1:]) #Output: ['2.banana', '3.cherry', '4.orange', '5.kiwi', '6.melon', '7.mango']
print(thislist[:5]) #Output: ['1.apple', '2.banana', '3.cherry', '4.orange', '5.kiwi']
print(thislist[2:5]) #Output: ['3.cherry', '4.orange', '5.kiwi']
print(thislist[::3]) #Output: ['1.apple', '4.orange', '7.mango']
print(thislist[1::2]) #Output: ['2.banana', '4.orange', '6.melon']
print(thislist[1:6:3]) #Output: ['2.banana', '5.kiwi']
#1

Fluing na lista de Python

list_example = ["python","ruby","java","javascript","c#","css","html"]
print(list_example[3])#javascript
print(list_example[0])#python
print(list_example[6])#html
print(list_example[0:3]) #will print the programming language under python and javascript
print(list_example[:3]) all languages under python to javascript
Programmer of empires

LISTA FORIAÇÃO EM PYTHON

# List slicing
friends = ["Harry", "Tom", "Rohan", "Sam", "Divya", 45]
print(friends[0:4])
print(friends[-4:])
Coding boy Hasya

fatia de python

#slicig
b=("hello world")
print(b[2:])
Beautiful Bear

Lista de fatiamento

This slice object can take three arguments; 
slice(start, end, step)

fruits = ["apple", "banana", "peach", "pear", "plum", "orange"]
x = slice(1, 4, 2)
fruits[x]
Gorgeous Goldfinch

Fatia de python

# Accessing tuple elements using slicing
my_tuple = ('p','r','o','g','r','a','m','i','z')

# elements 2nd to 4th
# Output: ('r', 'o', 'g')
print(my_tuple[1:4])

# elements beginning to 2nd
# Output: ('p', 'r')
print(my_tuple[:-7])

# elements 8th to end
# Output: ('i', 'z')
print(my_tuple[7:])

# elements beginning to end
# Output: ('p', 'r', 'o', 'g', 'r', 'a', 'm', 'i', 'z')
print(my_tuple[:])
SAMER SAEID

Respostas semelhantes a “Lista de fatiamento”

Procure respostas de código populares por idioma

Procurar outros idiomas de código