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



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

Removing Elements
There are situations that may warrant you to remove an item in a list. For
instance,  a  player  may  decide  to  remove  a  bird;  he  shoots  down  from  the
sky from the active list. Perhaps, you want to delete a customer’s account or
cancel their account. You can remove such detail from the list. You can use
the following two ways to remove elements in a list.
Remove Items Using del Statement
Python provides a unique way of removing or deleting an item if you know
the position of such an item from the list. Look at the code below:
kitchen_item  =  [“pot,”  “kettle,”  “fridge,”  “dishwasher,”  “microwave,”
“knife,” “bowls”]
print(kitchen_item)
del kitchen_item [4]


print(kitchen_item)
What did you think will be deleted from the snippet above? If your answer
is a dishwasher, then you are wrong. Remember that Python index begins at
0.  This  means  we  start  counting  0  from  the  first  element.  Therefore,  the
final output will be:
[“pot,” “kettle,” “dishwasher,” “microwave,” “knife,” “bowls”]
You can remove any item from the position of your choice.



Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   37   38   39   40   41   42   43   44   ...   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