“Unpack List Python” Respostas de código

Unpack List Python

# unpack a list python:
list = ['red', 'blue', 'green']

# option 1
red, blue = colors

# option 2
*list
Repulsive Raven

Unpack List Python

def print_items(item1, item2, item3, item4, item5, item6):
  print(item1, item2, item3, item4, item5, item6)

fruit = ["apple", "banana", "orange", "pineapple", "watermelon", "kiwi"]

# deconstructs/unpacks the "fruit" list into individual values
my_function(*fruit)
Chrysler

Python Unpback List

elems = [1, 2, 3, 4]
a, b, c, d = elems
print(a, b, c, d)
# 1 2 3 4

# or
a, *new_elems, d = elems
print(a)
print(new_elems)
print(d)
# 1
# [2, 3]
# 4
patrick204nqh

Respostas semelhantes a “Unpack List Python”

Perguntas semelhantes a “Unpack List Python”

Mais respostas relacionadas para “Unpack List Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código