Skip to content
Natuurondernemer
    Gennaio 8, 2021 by admin

    GeeksforGeeks

    GeeksforGeeks
    Gennaio 8, 2021 by admin

    pop() è una funzione integrata in Python che rimuove e restituisce l’ultimo valore dalla lista o il valore dell’indice dato.

    Sintassi :

    list_name.pop(index)

    Parametro :

    index (optional) - The value at index is popped out and removed.If the index is not given, then the lastelement is popped out and removed.

    Returns :

    The last value or the given index value from the list

    Exception :

    When index is out of range, it returns IndexError

    Codice #1 :

    list1 =

    print

    (list1.pop())

    print("New List after pop : ", list1, "\n")
    list2 =
    print

    (list2.pop())

    print(list2.pop())
    print(list2.pop())

    print("New List after pop : ", list2, "\n")

    
    

    
    

    Output :

    6New List after pop : 4('cat', 'bat')3New List after pop : 

    Codice #2 :

    list1 =

    print

    (list1.pop(), list1)

    print(list1.pop(0), list1)

    
    

    
    

    Output :

    6 1 

    Codice #3 : IndexError

    list1 =
    print(list1.pop(8))

    
    

    
    

    Output :

    Traceback (most recent call last): File "/home/1875538d94d5aecde6edea47b57a2212.py", line 5, in print(list1.pop(8))IndexError: pop index out of range

    Esempio pratico :
    Una lista fruit contiene fruit_name e la proprietà che dice il suo frutto. Un’altra lista consumare ha due elementi succo e mangiare. Con l’aiuto di pop() e append() possiamo fare qualcosa di interessante.

    fruit =,, ]
    consume =
    possible =

    foritem infruit :

    foruse inconsume :
    item.append(use)

    possible.append(item)

    item.pop(-1)
    print(possible)

    
    

    
    

    Output :

    , , , , , ]
    Tag articolo :
    Practice Tags :

    Previous article21 cose da fare quando il tuo ragazzo è arrabbiato con teNext article Baciami o uccidimi: Sexual Desperation and Identity Erasure in Cat on a Hot Tin Roof

    Lascia un commento Annulla risposta

    Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

    Articoli recenti

    • Trovare se stessi (e gli altri…) negli annuari online
    • Come impostare un bitcoin ASIC miner
    • Cos’è un sito Superfund?
    • I vermi sanguigni con esca da pesca hanno morsi di api
    • Ecolalia: I fatti oltre il “parlare a pappagallo”, lo scripting e l’eco
    • Citazioni del Signore delle Mosche
    • A Beginner’s Guide to Pegging
    • 42 ricette sane di zuppa Crockpot
    • 3 rischi sorprendenti della cattiva postura
    • Pesce Betta femmina

    Archivi

    • Aprile 2021
    • Marzo 2021
    • Febbraio 2021
    • Gennaio 2021
    • Dicembre 2020
    • Novembre 2020
    • Ottobre 2020
    • Settembre 2020
    • Agosto 2020
    • Luglio 2020
    • Giugno 2020
    • Maggio 2020
    • Aprile 2020
    • DeutschDeutsch
    • NederlandsNederlands
    • EspañolEspañol
    • FrançaisFrançais
    • PortuguêsPortuguês
    • ItalianoItaliano
    • PolskiPolski

    Meta

    • Accedi
    • Feed dei contenuti
    • Feed dei commenti
    • WordPress.org
    Posterity WordPress Theme