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


Append an Element to the List End



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

Append an Element to the List End
This  method  is  the  simplest  to  use  when  adding  an  element  to  a  list.  By
appending the element, you add the item to the list end. Remember, we use
the word “append” to add new items. However, for consistency purposes, I
will use our previous kitchen_item example to explain. In this example, we
will add cooking gas to the list.
kitchen_item  =  [“pot,”  “kettle,”  “fridge,”  “dishwasher,”  “microwave,”
“knife,” “bowls”]
print(kitchen_item)
kitchen_item.append(“spoon”)
print(kitchen_item)


The append()method allows us to add an element at the end of the list. The
output will be:
[“pot,” “kettle,” “fridge,” “dishwasher,” “microwave,” “knife,” “bowls,”
“spoon”]
If you have an empty list, you can utilize the append() method to add a new
list. Assuming we want to add a new list element such as pot, kettle, and
microwave, we can do that as follows:
kitchen_item []
kitchen_item.append(“pot”)
kitchen_item.append(“kettle”)
kitchen_item.append(microwave”)
print(kitchen_item)
This code will produce:
[“pot,” “kettle,” “microwave,”]
It is very common to build the list this way because you may not know the
Download 2,02 Mb.

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