All language subtitles for 5. Ternary Operator

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

I want to talk to you about another way to do conditional logic.

We saw the F L F and then the else statement but there's another way called the ternary operator.

Now this is still the same as the else f or if else statements but it's a shortcut so you can only use

these on certain conditional logic so it doesn't mean that hey this is just the an entirely new way.

This is a shortcut in a sense for you to make your code a little bit cleaner.

Let's have a look.

By the way these ternary operators can also be called conditional expressions.

And when you hear the word expression that should mean something to you right.

It's an expression because it evaluates to a value.

So a ternary operator or a conditional expression is an operation that evaluates to something based

on the condition being true or not.

And it's actually a new feature of Python.

As of version two point four.

So let's have a look the way we use this is to say is condition if this is true then do this.

So this is the condition if true.

And bear with me here it is a little bit confusing at first.

We say if and here we give condition otherwise condition

else.

All right.

That is that is a little confusing so look let's go through it so the f is going to check this condition

so it doesn't actually start with here.

It's going to say hey if this condition now this is going to evaluate to their true or false if it's

true then we're going to do this.

Otherwise we're going to do this.

So let me show you an example of how that would work.

Let's say we're trying to determine if well if a user is your friend.

So we'll say is a friend.

And here we can set to True or false for a friend.

Maybe we can check on Facebook if users can message you or on Twitter whether Twitter users can give

you direct messages.

Well here and let's do can message.

And here we can do our ternary operator.

We're going to say message aloud If so this is if the condition is true the condition is hey is this

person your friend.

Otherwise condition.

That is false.

Well I'm going to say not allowed to message and you can see here that this is a one liner though it

looks like two lines.

But you can see over here that it's not really is just that we're wrapping so we can see the entire

code so let's run this and see what can message prints.

If I run this message is allowed because well we've assigned message aloud to Ken message because while

the condition was true if this person wasn't my friend and I run this not allowed to message because

of the condition that if condition evaluates to false I know the ordering here can be a little bit confusing

so you might have to look at it a couple times and you do need to use it a few times to really remember

it but this is the general rule condition if true if condition else condition if not a false if false

can't spell.

All right.

A nice shorthand way to do something when a condition is either true or false or evaluates to true or

false.

All right I'll see you in the next video.

Bobby.

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