All language subtitles for 1. For Loops How and Why

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian Download
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

0 In this lecture I'll explain one of the most important concepts in Python programming, that is for loops. 1

I'll use an example, so you not only understand the syntax how to write a for loop, but you'll also understand 2

why you should use for loops. 3

Let's say we've got these temperatures for Monday so maybe this was recorded in the morning in midday, 4

and that in the evening. 5

So how can we make a program that prints out the rounded values of each of these values like that? 6

So that would be the expected output. 7

You can see it down here. 8

As you'd get 9 because 9.1 rounded up to the whole number will be 9, and then 9

8.8, 9 again. 10

And 7.8, 8. 11

How can we do that? 12

So we need to find a way to access the items of the list and you know a method already how to 13

access list items which is using indexes. 14

So if you want the first one you use zero. 15

So you want to print out the first item, that however would print out 9.1, you want the rounded 16

version of nine points one which is maybe you want to look, to have a look at what functions you have 17

available. 18

Like that. 19

So have a quick look here, and you'll be able to find a round. So round which means you want to round 20

a number, so round 9.1, you get 9, and in our case the number we'd like to round up is this 21

expression. 22

So we want to play round here and in parentheses put that expression. 23

So that's number, 9.1. 24

So give it a try before rewriting the entire code and that's fine. 25

Do that again. 26

Write. 27

But with 1 and with 2, executes, and you get the expected output, okay, that's fine, it works but what 28

if you had a big list of 100 items? You'd end up with 100 lines of code. 29

Well, I can show you how to do that with just two lines of code instead. 30

This how you do it. You use a for loop for temperature. 31

Just choose a name for a variable for temperature in. You see how these keywords are highlighted. 32

So these are actually Python reserved words. 33

Temperature is just a variable. 34

That's why it's in black. In Monday temperatures, use a colon. 35

And what happens after the colon? 36

I told you in the earlier video. 37

Well indentation which happens automatically in Visual Studio Code, four spaces. 38

What do we want to do for each of the temperatures? 39

Well, we want to print out the round form of temperature. 40

Just like that, save, execute. 41

And this is the output. 42

So in just two lines of code we are able to execute some commands for all the items of an array which 43

a least in this case, but it can also be a string. 44

For example for the letter in "hello", print letter. 45

And hello is printed out there. 46

And of course you can do whatever you like there, title. 47

Get the first item which is the letter. 48

So the letter would be capitalized like that. 49

So let me go one more time through these two lines to explain them what they mean. 50

So what the loop does is for temperature in Monday temperatures. 51

So you are creating a variable. 52

And what the loop does is it goes through all these items one by one with loops. 53

So in the first iteration temperature will be equal, 54

so the variable will be equal to 9.1. 55

Therefore the round function will round up nine point one and print it out here. 56

And if there are more lies in here, for example print "Done". 57

If you do that you see if there is another more line like after 9, this line is executed. 58

So you get the string "Done" print it out. 59

If there are more lines those lines will be executed. 60

If there is no more lines, then the execution goes again on the top of the for loop, and the loop gets the 61

second item this time. 62

So temperature this time will be equal to 8.8 and the same thing happens again, rounded it up, 63

print it out. 64

"Done" is also printed out, goes to the next line. 65

7.6. 66

And so one, and then after 7.6 the loop tries to see if there are more items in this array. 67

If there are no more items what happens is that this indented block, the execution of this block finishes 68

and Python goes to the next two lines to execute what's left in the script.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.