Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools


Using the pop() Method to Remove an Item



Download 2,02 Mb.
Pdf ko'rish
bet42/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   38   39   40   41   42   43   44   45   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Using the pop() Method to Remove an Item
There  are  situations  where  you  want  to  use  an  item  value  after  removing  it  from  the  list.  For
instance,  you  want  to  know  the  coordinates  of  the  bird  you  shot,  to  enable  you  to  draw  an
explosion in such a position. The function of the pop()method is to remove the last item in the list.
For clarity, let us pop an example.
kitchen_item = [“pot,” “kettle,” “fridge,” “dishwasher,” “microwave,” “knife,” “bowls”]
print(kitchen_item)
popped.kitchen_item = kitchen_item.pop()
print(kitchen_item)
print(popped.kitchen_item
I won’t explain the first two lines since you are already conversant with it. However, if you forget,
I will refresh your memory. The first line begins by declaring “kitchen_item” as a variable with
values  including  pop,  kettle,  fridge,  dishwasher,  microwave,  knife,  and  bowls.  The  second  line
prints out the items in the kitchen_item list.
In  the  third  line,  we  popped  a  value  from  our  list  and  store  the  value  to  the  new  variable
“popped.kitchen_item”  additionally,  we  print  out  the  remaining  items  in  the  kitchen_item  list.
From the code above, our output will be:
[“pot,” “kettle,” “fridge,” “dishwasher,” “microwave,” “knife,” “bowls”]
[“pot,” “kettle,” “fridge,” “dishwasher,” “microwave,” “knife”]
bowls
The  first  line  shows  the  complete  kitchen_items,  whereas  the  second  shows  the  remaining  items
after the popped method was used. Finally, line three shows the item removed from our list.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   38   39   40   41   42   43   44   45   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish