“Listen Sie ein Beispiel in Python auf” Code-Antworten

So verwenden Sie die Liste in Python

seller = ['apple', 'banana', 'avocado'] # the list
new_item = 'kiwi' # new item in the store
seller.append(new_item) # now it's have been added to the list
LazyGoat

Listen Sie ein Beispiel in Python auf

# list of numbers
n_list = [1, 2, 3, 4]

# 1. adding item at the desired location
# adding element 100 at the fourth location
n_list.insert(3, 100)

# list: [1, 2, 3, 100, 4]
print(n_list)

# 2. adding element at the end of the list
n_list.append(99)

# list: [1, 2, 3, 100, 4, 99]
print(n_list)

# 3. adding several elements at the end of list
# the following statement can also be written like this:
# n_list + [11, 22]
n_list.extend([11, 22])

# list: [1, 2, 3, 100, 4, 99, 11, 22]
print(n_list)
Mohammed Basith

Ähnliche Antworten wie “Listen Sie ein Beispiel in Python auf”

Fragen ähnlich wie “Listen Sie ein Beispiel in Python auf”

Weitere verwandte Antworten zu “Listen Sie ein Beispiel in Python auf” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen