“So fügen Sie ein Tupel an eine Liste an” Code-Antworten

Python Append an die Tuple -Liste angehängt

apple = ('fruit', 'apple')
banana = ('fruit', 'banana')
dog = ('animal', 'dog')
# Make a list with these tuples
some_list = [apple, banana, dog]
# Check if it's actually a tuple list
print(some_list)
# Make a tuple to add to list
new_thing = ('animal', 'cat')
# Append it to the list
some_list.append(new_thing)
# Print it out to see if it worked
print(some_list)
Random boi

So fügen Sie ein Tupel an eine Liste an

a_list = []
a_list.append((1, 2))       # Succeed! Tuple (1, 2) is appended to a_list
a_list.append(tuple(3, 4))  # Error message: ValueError: expecting Array or iterable
Arrogant Armadillo

Ähnliche Antworten wie “So fügen Sie ein Tupel an eine Liste an”

Fragen ähnlich wie “So fügen Sie ein Tupel an eine Liste an”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen