All language subtitles for 31. Walrus 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
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

Welcome back.

Let's talk about the walrus operator, and this one is a fun one because, well, it looks like a walrus.

It looks like this sea looks like, well, Google walrus, if you don't know what that is, it's an

animal.

And it kind of looks like that.

Just Google this.

All right.

We're getting distracted.

So what is this new operator we're going to learn about?

The reason I want to teach you this is because I also want to teach you how to learn about new features

in Python, for example.

This is a new feature.

If I go to the Python documentation here, usually what Python does with each new version, they create

a what's new in Python document.

So you might see what's new in Python three point nine.

What's new in Python, three point ten.

And it gives you a summary of some of the new features added to the language, because, remember,

a language is constantly evolving.

So let's say you want to learn about new three point eight features, because let's say the Reppel you're

on now has three point eight.

So it's able to understand the new features like the Walrus operator that we weren't able to write before

this version.

So I would go into the documents and see what's new in Python three point eight.

And we see one of the first things is the assignment expression.

Called the Walrus operator.

So what I would usually do is just read about the summary.

Of what this does and you can learn about all the new features added in this version.

Now, let's just focus on the Walrus operator, because it is useful and also kind of fun to learn about

what this new Syntex does is it assigns value to variables as part of a larger expression.

So usually you use it in an expression when something is being evaluated, like in an if statement,

maybe a while statement.

So let's play around with this and see what we can do.

So let's say we have a string and we'll call this string.

Hello.

Now in here.

Let's say I want to do a conditional statement, I'm going to say if.

Length of a.

Is greater than 10.

I want you to print a string that simply says too long.

And we'll say lenth a.

Elements.

Well, make sure I do that properly.

Now, if I click run here.

I get to log 14 elements and why is that?

Well, because each character here we have 14 elements because it's greater than 10.

This conditional block runs and we print out too long.

We have a length of 14 elements.

So where does the walrus operator come in?

Well, we're writing code and we're repeating ourselves here because we're calculating a length twice.

We're using this as a variable and doing some sort of a calculation multiple times because we want to

use it here and here.

But with a walrus operator, I can do exactly that, remember, if I go to the documentation it says

assigns values to variables as part of a larger expression.

So what I can do here is I can create another variable like NP and that says, well, Woolworth's operator

So Colin.

And equals little walrus there and this end is going to equal length.

So I'm just going to wrap this in brackets.

So we're evaluating this part of the expression and we're assigning the variable NP, whatever the outcome

of length A is.

So now NT is something that has the value of a.

So I can replace this.

And if I run this now.

Again, same thing.

So, again, what we can do is we can assign.

Values two variables as part of a larger expression.

For example, if I did and equals lenth a well, this isn't going to run, it's invalid syntax, but

because of the walrus operator we can do this now.

Let's do one more just to make sure we have it.

So let's say in here we're going to do a while loop while Loop is going to say and walvis operator.

Lenth a.

Again, we're going to do the same thing if it's less than this time, let's do one.

And while this is true, I want to print the value of RN and we're going to reassign the value of the

variable A to have one less letter.

So I can just do that with the minus one short form here.

So we're going to remove the last letter every time we loop through here so that the a variable, the

hello becomes smaller and smaller and smaller until.

It equals to one, and once it equals to one, the while loop is going to stop.

So let's just run this.

All right, we're getting true, true, true, and we made a bit of an error here because remember the

parentheses, we want to evaluate this first.

So if I run this again.

Fourteen, thirteen, twelve, eleven, ten.

This is the length of A that's being calculated every time and at the very end if I print.

And run it.

You see that we have each remaining.

There you have it, the walrus operator, you might not see it very often, it's essentially a way for

us to minimize doing calculations that are similar, let's say, inside of an if statement or a wild

statement where we want to do something based on a condition and then calculate that value again.

But this also hopefully teaches you how to look a new Python versions and learn about new features.

There's only a handful of features that get added to the language.

Most of the important ones have already been added.

But it's also good to keep an eye out on things as the language evolves so that whenever you see something

like a walrus operator and the code base, you now understand what it does and that it's part of the

language I'll see in the next one by.

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