# Python3-Programm zur Demonstration der Verwendung
# remove () Methode
# erstes Vorkommen 1 wird aus der Liste entfernt
list1 = [ 1 , 2 , 1 , 1 , 4 , 5 ]
list1.remove ( 1 )
print (list1)
# entfernt ' ein ' aus Liste 2
list2 = [ `a` , ` b` , `c` , ` d` ]
list2.remove ( `a` )
print (list2) Ausgabe: [2, 1, 1 , 4, 5] [`b`,` c`, `d `] Fehler: Er gibt ValueError zurück, wenn das übergebene Objekt nicht in der Liste vorhanden ist Code # 2: # Python3-Programm für Fehler in
# remove () method
# entfernt ' e ' aus Liste 2
list2 = [ `a` , ` b` , `c` , ` d` ]
list2.remove ( `e` )
print (list2) Exit: Traceback (letzter Aufruf zuletzt): Datei "/home/e35b642d8d5c06d24e9b31c7e7b9a7fa. py", Zeile 8, in list2.remove (`e`) ValueError: list.remove (x): x not in list Praktische Anwendung: Sobald Sie erhalten Sie die Liste, entfernen Sie alle Einsen aus der Liste und drucken Sie die Liste aus. Code # 3:
# Python3-Programm für den praktischen Einsatz
# 1 entfernen bis alle 1 aus der Liste entfernt sind
list1 = [ 1 , 2 , < Codeklasse = "Wert"> 3 , 4 , 1 , 1 , 1 , 4 , 5 ]
# Schleife bis alle Einsen gelöscht sind
while (list1. count ( 1 )):
list1.remove ( 1 )
print (list1)
| tr> Exit: [2, 3, 4, 4, 5 ]
Shop
Learn programming in R: courses $
Best Python online courses for 2022 $
Best laptop for Fortnite $
Best laptop for Excel $
Best laptop for Solidworks $
Best laptop for Roblox $
Best computer for crypto mining $
Best laptop for Sims 4 $
Latest questions
NUMPYNUMPY
psycopg2: insert multiple rows with one query
12 answers
NUMPYNUMPY
How to convert Nonetype to int or string?
12 answers
NUMPYNUMPY
How to specify multiple return types using type-hints
12 answers
NUMPYNUMPY
Javascript Error: IPython is not defined in JupyterLab
12 answers
Wiki
Python OpenCV | cv2.putText () method
numpy.arctan2 () in Python
Python | os.path.realpath () method
Python OpenCV | cv2.circle () method
Python OpenCV cv2.cvtColor () method
Python - Move item to the end of the list
time.perf_counter () function in Python
Check if one list is a subset of another in Python
Python os.path.join () method
|