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



Download 2,02 Mb.
Pdf ko'rish
bet60/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   56   57   58   59   60   61   62   63   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Using Loop in a Slice
Python allows the use of for loop in a slice to go through a subset of elements in the list. We can
create a loop to pass through the first four players on our list and display their names. Let us see
how that works.
united_players =[ “Rashford,” “Young,” “Pogba,” “James,” “De Gea”]
print (“My favorite Manchester United Players are:”)
for players in united_players [ :4]:
print(players.title())
Rather than the interpreter looping through the full list of players in line 3, it loops only through
the first four players in the team. Then our output will be:
My favorite Manchester United Players are:
Rashford
Young
Pogba
James
Slice comes handy in various situations, such as when you want to add the final score of a player in
a game when working with data or building a website application.
Tuples
If you want to store items, which can change during the course of the program, then the list works
perfectly for this situation. Modifying data or a list is very important when working with various
applications or creating web applications. Notwithstanding, at times, you may want a list of items
whose  value  doesn’t  change  throughout  the  program.  In  such  a  situation,  you  can  use  a  tuple  to
replace  using  a  list.  In  Python,  we  call  values,  which  cannot  change  throughout  the  life  of  the
program as immutable. Therefore, an immutable list can also be known as a tuple.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   56   57   58   59   60   61   62   63   ...   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