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



Download 2,02 Mb.
Pdf ko'rish
bet54/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   50   51   52   53   54   55   56   57   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

range() Function


This  function  is  a  unique  function  that  allows  a  programmer  to  easily  generate  a  sequence  of
numbers. In the example below, we can print a range of numbers from 6 to 15.
for scores in range(6, 15):
print(scores)
In as much as the code seems like printing the numbers from 6 to 15, however, it doesn’t print the
number 15. Our output will be as follow:
6
7
8
9
10
11
12
13
14
In our example below, the range() function prints only the numbers from 6 to 15. Well, this is the
product  of  the  off-by-one  behavior,  which  exists  in  most  programming  languages.  The  function
makes  the  interpreted  to  start  the  counting  process  at  the  initial  number  but  stops  at  the  second
number before reaching the number indicated. However, if you wanted to print out the number 15,
that means you have to extend the stopping point by one. In this case, it is 16. Therefore, your code
will be as follows:
for scores in range(6, 16):
print(scores)
Moreover, your output will be:
6
7
8
9
10
11
12
13
14


15
If your output doesn’t match what you wanted when using the range() function, then you have to
adjust the ending value by 1.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   50   51   52   53   54   55   56   57   ...   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