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



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

What is a Tuple?
A  tuple  is  similar  to  the  list  I  explained  earlier.  However,  we  use  parentheses  for  tuple  as  an
alternative to square brackets used in a list. You can access each element after defining a tuple by
using each index. It is similar to what you would do if you want to access a list.
For instance, let us take the length and width of a room to be 200 by 100, which will always remain
the same size unless the building is destroyed. Therefore, putting the length and width into a tuple,
we have ensured that its size won’t change.


size = (200, 100)
print(size[0])
print(size[1])
What  we  have  done  in  the  first  line  is  to  define  the  tuple  size  by  using  parentheses  rather  than
square brackets. Then in the second and third lines, we print the elements individually. Then save
and run the program, your output will be:
200
100
Let me modify the program to show you when Python recognizes an error when you try to alter the
tuple value.
size = (200, 100)
size[0] = 220
In the second line, I try to change the value from 200 to 220. However, Python will return an error.
We try to change a tuple, which isn’t possible with such an object.

Download 2,02 Mb.

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