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



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

Modifying Elements
You can modify elements in an element similar to how you can access it.
Furthermore,  the  same  syntax  applies  to  when  you  want  to  access  an
element. To modify an element, you will use the list name, followed by the
index element that you want to modify, and then provide the new value to
want to change. Well, this may sound foreign; however, let me use a simple
example to illustrate how you can do this. For instance, we want to change
dishwasher to spoon in the example below, how can you do that.
kitchen_item  =  [“pot,”  “kettle,”  “fridge,”  “dishwasher,”  “microwave,”
“knife,” “bowls”]
print(kitchen_item)


kitchen_item[3] = “spoon”
print(kitchen_item)
The first two lines of code define our original list, which contains the word
“dishwasher.” The third line changes the element from dishwasher to spoon.
If you do it correctly, you will get the output as:
[“pot,” “kettle,” “fridge,” “dishwasher,” “microwave,” “knife,” “bowls”]
[“pot,” “kettle,” “fridge,” “spoon,” “microwave,” “knife,” “bowls”]
You can change any element irrespective of where it is positioned.
Adding Elements
At times, you may want to add an element in a list to expand your program.
Remember  the  bird  scenario,  where  you  have  additional  new  birds  each
time you shoot. It doesn’t apply to that alone; you may want to expand your
database to include new users or add new items to a list. Python provides
various means of adding elements in a list. In this section, we will focus on
two ways you can do this as a beginner.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   34   35   36   37   38   39   40   41   ...   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