All language subtitles for 6. Short Circuiting

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
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
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

It's time to talk about another topic that sounds a lot more confusing.

Short circuiting than it actually is.

It's quite simple short circuiting looks something like this.

Remember when I taught you the word and so we can use let's say for example is friend

equals too true and let's say is user is equal to true and I can do an expression here saying is friend

and is user now in here.

When we run this let's printed here just so we can see if I run this I get true because both of these

evaluate to TRUE SO THAT IF I HAD THIS AS AN F block let's say if it was if is friend and is user print.

Best friends forever now.

Short circuiting can be done when we use something like for which we haven't seen before but again you

can see here that it's highlighted in blue so it is a keyword.

A python keyword now or says if either one of these conditions are true then run this piece of code.

So if I run this I get.

Best friends forever.

Now let me ask you this.

Which operation do you think is more performance.

The or or the end.

Is there a difference.

As a matter of fact there is because of short circuiting.

You see when I do or here because I only care if either one of these is true the Python interpreter

is going to say if it's friend and it's going to evaluate that and say oh this is this is true and then

it's going to see the word or and it's going to say hey I don't care what this is.

Maybe this is a really heavy operation or something that I need to look up.

Well I don't really care because this is already true whether this is true or this is false.

I don't really care because either way I'm going to have to print this as you can see it still prints.

Best friends forever so short circuiting happens when the interpreter is smart enough to say I already

did enough work.

I don't care what this is this is just wasted work if I do it.

So I'm going to short circuit and say hey I'm going to just ignore this and I'm going to start printing

so using or is a little bit more efficient but again it depends on what you need.

If you need to check if both is friend and is user true you'll have to use and but this works both ways

with and as well.

For example if its friend is false this is going to get short circuited because I'm going to say hey

if his friend is false.

Well I don't really care what is user is because there's no way that both of these are true.

I've already seen that one of them is false so I'm going to ignore this and I'm going to print this.

And when I say I I mean our good ole friend Python interpreter.

Now this topic of short circuiting doesn't really get taught in beginner Python courses but now if you

hear this maybe hear this in an interview as you can see it sounds a lot more difficult than it actually

is.

And frankly it makes a lot of sense right.

We want our machines to be efficient and it is quite efficient due to short circuiting I'll see in the

next one.

Bobby.

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