# Python3-programma om gebruik te demonstreren
# verwijder () methode
# eerste exemplaar 1 is verwijderd uit de lijst
lijst1 = [ 1 , 2 , 1 , 1 , 4 , 5 ]
list1.remove ( 1 )
print (lijst1)
# verwijdert ' een " van lijst 2
list2 = [ `a` , ` b` , `c` , ` d` ]
list2.remove ( `a` )
print (lijst2) Uitvoer: [2, 1, 1 , 4, 5] [`b`,` c`, `d `] Fout: Het retourneert ValueError wanneer het doorgegeven object niet aanwezig is in de lijst Code #2: # Python3-programma voor fout in
# verwijder () methode
# verwijdert ' en ' van lijst 2
list2 = [ `a` , ` b` , `c` , ` d` ]
list2.remove ( `e` )
print (lijst2) Afsluiten: Traceback (meest recente oproep laatst): Bestand "/home/e35b642d8d5c06d24e9b31c7e7b9a7fa. py", regel 8, in list2.remove (`e`) ValueError: list.remove (x): x niet in lijst Praktische toepassing: Zodra u ontvang de lijst, verwijder alle enen uit de lijst en druk de lijst af. Code #3:
# Python3-programma voor praktisch gebruik
# verwijder 1 totdat alle 1 uit de lijst zijn verwijderd
list1 = [ 1 , 2 , 3 , 4 , 1 , 1 , 1 , 4 , 5 ]
# loop totdat alle enen zijn verwijderd
while (list1. count ( 1 )):
list1.remove ( 1 )
print (lijst1)
| tr> Afsluiten: [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
|