Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
When looping in Python one of the most common tools is this range function that we get out of the box
with Python and you see here that range well is a Range object a special type of object in Python that
returns an object that produces a sequence of integers from start to stop let's explore that are a little
bit more if I print here a range and I say range one hundred and I click Run I get range of zero to
one hundred.
So it looks like a tulpa but it's not.
It's a Range object and it's a special type of object and a range you can give it like this which gives
you a default of zero to whatever you give it which is 100.
Or you can just simply Type 0 one.
And if I click Run it's the same thing but where range becomes really useful and you'll see this in
99 percent of cases in Python is in for loops you see besides topples and lists and sets and dictionaries
and strings.
You can iterate over a range.
So for example if I do for i in range and there's a say item or in our case letters to number in range
and in here I do print no if I run this you'll see that I'll get numbers 1 to 100.
And why is this useful.
Well using a range I was able to loop a hundred times as you can see all the way till 99 because our
count starts at 0 and we're able to loop as many times as I want so I can tell the loop maybe we want
to loop a certain number of times maybe you won't want to loop 10 times where I can tell the loop how
many times to run it's extremely useful maybe here we're performing some action where it says I don't
know email the email list so we want to send 10 emails to an email less for example.
Well again I can just click Run and I sent that email while a bunch of times 10 times.
Another neat trick is that while you might not even need no great we're not really using it in our code
and often while you'll find in python programs is If a programmer doesn't need this variable you just
do an underscore and this is just a variable.
I mean you could use it like this and you'll still get these numbers but it just indicates to other
people that hey I don't really care what this variable is.
I'm just trying to use range so that we can loop over things.
Let's say 10 times now range also comes with a third parameter.
And what that is is they step over.
So if I do too.
And by the way.
Default is one here.
If I do two it jumps from zero to 10 by two which is very very handy.
So what is the range.
Well range creates a special kind of object that we can iterate over OK.
What if I do minus.
Right here.
What if I do minus one.
Well if I run this Hmm that's not going to work because well let me show you why.
If I change this to zero and 10 and I do minus one
it's going to go in the opposite direction but if I did just ten and zero that's not going to work.
If we want to do something in reverse we just have to make sure that we add that minus one or if we
want to step back twice.
Then we click Run.
So you have a lot of options to play with the range.
You can do ascending descending one final thing.
Another place that you might see ranges.
And like I said most of the time they're in for loops but he can also do something interesting like
let's say a range of 10 and then if we wrap this in a list remember a list function allows us to convert
something to a list.
If I run this does you see that let's simplify this so that this range is going to just be too if I
click Run you see that I loop two times and in here I'm going to print first of all I'm going to create
a range and it a rebel object that has 10 items and then I'm going to convert that into a list so you
can see here zero to nine into a list.
So this is a quick way to create a list that ball has integers a neat trick that you'll definitely use
along your program or journey I'll see in the next one.
But by.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.