background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Уроки Python с нуля / #5 – Условные операторы"

input logo icon
Table of contents
|

Table of contents

0:00
Начало
0:16
Что такое условные конструкции?
0:40
Создание простого условия
3:00
Проверка данных от пользователя
4:27
Форматы проверок
5:33
Вложенные условия
8:57
Проверка булевых переменных
11:36
Оператор «else»
13:18
Оператор «elif»
16:38
Несколько условий
20:18
Тернарный оператор
22:40
Заключительная часть
Video tags
|

Video tags

python if else
python условия
python
питон
python уроки
python для начинающих
python с нуля
уроки python
питон с нуля
гоша дударь python
python tutorial
python tutorial for beginners
пайтон
выучить python
питон уроки
learn python
python programming
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:01
study various conditional constructions
00:00:03
that exist in the Python language
00:00:05
and before starting, I would like to
00:00:07
recommend the site and these Prager dot
00:00:09
com on this site you will find them for
00:00:10
homework and a lot of other useful
00:00:12
information link to this lesson on the site
00:00:14
will be in the description of this video,
00:00:16
for starters, what is a conditional
00:00:17
construction? Due to the conditional construction,
00:00:19
you and I can check a
00:00:21
certain expression and if it
00:00:23
turns out to be true, then in this case we will
00:00:26
execute one piece of code;
00:00:27
if it turns out to be incorrect, but we
00:00:29
can execute another piece of code
00:00:31
accordingly Due to conditional
00:00:33
constructions, we can simply
00:00:34
execute different code with you depending on
00:00:36
different conditions. To implement a conditional
00:00:39
construction,
00:00:40
we will need to use a
00:00:42
keyword such as willow. If we are talking
00:00:44
about other programming languages, then there are
00:00:46
always parentheses after them with
00:00:49
5 in Python language produces all the
00:00:51
extra characters, not they were removed,
00:00:53
so here after
00:00:55
iv we don’t need to add anything additional
00:00:56
and we just indicate a
00:00:59
certain condition with you,
00:01:00
let’s first indicate what is there and the
00:01:02
simplest possible, for example, if 5
00:01:04
is equal to 5, then in this case we are with
00:01:06
you we will display something on the screen
00:01:08
here, for example, it will be written with
00:01:10
it turns out that this piece of code can be
00:01:12
read as follows: if 5 is
00:01:15
equal to this, then in this case we will
00:01:18
execute that piece of code that
00:01:19
is located after the colon and that is separated by the
00:01:22
same number of indents, you
00:01:25
can notice that here is the editor, he
00:01:27
automatically created a
00:01:29
certain indentation for me and, accordingly,
00:01:31
all this code which will be located
00:01:33
at the same number of indentations,
00:01:35
it will be executed if
00:01:38
this condition works for me, at the moment
00:01:40
I have only one line of code here, well, I have it
00:01:43
will work if
00:01:45
this condition turns out to be true
00:01:46
at the moment, of course, the conditions
00:01:48
will be one hundred percent true because 5
00:01:50
is equal to 5, the law of mathematics, and if this is
00:01:54
launched, I will have
00:01:55
values ​​c displayed here at the same time, if
00:01:58
I need to execute several lines of
00:01:59
code then in this case, it simply
00:02:01
translates to a new line here, and
00:02:04
for example, here I can once again write
00:02:05
something like let’s say let’s say three
00:02:07
exclamation marks, if I run this,
00:02:09
then we notice what is output from and there
00:02:11
are also three!
00:02:13
other signs, so we get
00:02:15
certain conditions with you,
00:02:17
if this condition turns out to be true, the
00:02:19
one that is located after
00:02:22
the colon and that is separated by the same
00:02:25
number of indents is satisfied, for example, let me
00:02:27
try to indicate some incorrect
00:02:29
condition here, for example, I will say that if 5
00:02:33
we have more than 5 Well, obviously this is
00:02:35
not true because for us 5 is equal to 5, well,
00:02:37
no more, but let’s allow such a condition by decree,
00:02:40
then if we have this condition
00:02:42
true, then only in this case the code
00:02:43
should be executed; if it is
00:02:45
incorrect, then the code will not be executed
00:02:47
if I run this now nothing is not
00:02:49
displayed on the screen because the condition
00:02:51
initially turned out to be incorrect, let's
00:02:53
delete all this for now and let's
00:02:55
better try to write some conditions that are not super
00:02:57
primitive, more
00:02:58
complicated, more interesting conditions for
00:03:01
this, I propose to create some kind of
00:03:02
variable and let it be called
00:03:04
someday, perhaps even I I’ll call it
00:03:06
user data,
00:03:07
this is in no way related to the information that we
00:03:09
will receive from the user and
00:03:11
we will receive this information through the
00:03:13
input method. I also suggest immediately
00:03:15
converting this
00:03:19
into an integer and here let’s write
00:03:21
something like enter a number here So in
00:03:24
this way we wo n’t run this for now, let’s
00:03:27
better write some checks and
00:03:28
here we’ll write down
00:03:30
this condition itself a little lower, we’ll write the
00:03:32
keyword if and then I say that
00:03:34
if userdata, that is, if the data from
00:03:37
the user, for example, it will be greater
00:03:39
than the number 5 here only in this case, it
00:03:42
will be written on our screen that, for
00:03:45
example, we would avoid zen five, that is, for
00:03:49
example, it will be written here that
00:03:50
the number is greater than 5 if I now
00:03:53
run this and for example, I see the number 6 in this
00:03:56
case, this condition is triggered and we
00:03:58
have the user writes some information
00:04:00
that the number is greater than 5, but
00:04:04
if I run it again and see the number,
00:04:06
for example 4, in this case nothing
00:04:09
additional is displayed on the screen for
00:04:11
the reason that we no longer have this
00:04:13
check correct, we have
00:04:15
entered a number which was less than 5
00:04:17
and, accordingly, all this code that
00:04:19
was after the colon and that was
00:04:21
separated by the same amount of indentation
00:04:23
all this code did not work
00:04:25
for us and it happened in addition to
00:04:26
checking for equality and also assigning
00:04:29
more, here we can also check for a
00:04:31
value less than value is less than or
00:04:34
equal to assignment greater than or equal to assignment
00:04:37
equality of course we can check well and
00:04:39
assignment is not equality these
00:04:41
are the checks here and let’s
00:04:43
assume that if I now set up a
00:04:45
check in this format
00:04:47
then what do you think when we when
00:04:50
we will display this one here
00:04:51
piece of code
00:04:52
it will be displayed every time you and I
00:04:54
enter a number
00:04:55
that will not be equal to the value 5 because
00:04:58
we will now check we have written the following check with you
00:05:01
if our value from the user is not
00:05:03
equal to the value 5
00:05:05
then in this case we execute the code that
00:05:07
is located here in the conditional statement,
00:05:10
so if I now run the form, for example,
00:05:12
the number 4 ok, everything worked absolutely
00:05:14
correctly, if I run it again and see
00:05:17
the number 5, then all our checks are
00:05:19
now incorrect and because we
00:05:21
checked that if it is not equal to 5, then
00:05:23
we execute the code now is equal to 5,
00:05:26
so the code here inside us did not
00:05:28
execute such checks here
00:05:30
you can carry out, of course, inside
00:05:33
one condition you can write
00:05:35
some other condition,
00:05:36
again the main thing is to maintain the same
00:05:38
number of indents so that it is here
00:05:41
for all lines the code was well, let’s say
00:05:43
let’s write
00:05:45
some more conditions here, for example,
00:05:46
here I’ll point out that again our userdata works
00:05:49
if it’s more than the value
00:05:52
for example 6 in this case, let’s in
00:05:55
this case we’ll just
00:05:56
display this text here here, in this
00:05:58
case, we will write that we are in
00:06:00
place, well, let’s say that we just entered this
00:06:02
kind of conditions, if now
00:06:04
I run this and let’s see, for example, the number 7,
00:06:07
then in this case, first of all, we notice
00:06:09
that we are entered, we are in place, yes, that is
00:06:11
this condition turned out to be true, so
00:06:13
this piece of code worked, then we
00:06:15
had another condition here, this condition
00:06:18
also turned out to be true because we entered
00:06:20
the number 7 and accordingly the condition
00:06:22
turns out to be true and therefore we were
00:06:24
shown another message
00:06:25
at the same time if I enter for example number
00:06:28
4 then in this case we just went
00:06:31
into this condition, here we were executed
00:06:32
by a piece of code and this condition did
00:06:35
not work anymore, so the next
00:06:36
piece of code
00:06:38
was executed and here is an important point on the
00:06:40
basis of which it is easy to make a mistake, the
00:06:41
thing is that you need keep track of
00:06:43
all the indentations at the moment I have
00:06:46
this development environment for software and charms,
00:06:48
it automatically adds the
00:06:50
same indents to me
00:06:51
if somewhere here I delete one
00:06:54
specific space, then
00:06:56
an error will immediately be raised because at
00:06:58
the moment if you write it
00:06:59
in this spirit,
00:07:00
then the interpreter simply won’t understand what’s
00:07:03
going on here because
00:07:05
this is a line of code that seems to
00:07:07
belong to this condition, and then
00:07:09
I have a different number of spaces and
00:07:11
the interpreter just won’t understand what it’s for
00:07:14
at all This
00:07:15
next piece of code belongs, so it’s
00:07:18
very important to keep track of all these
00:07:19
spaces and all these indentations
00:07:22
because it is through them that
00:07:24
nesting is indicated,
00:07:25
which code belongs to what,
00:07:27
if I write here, for example,
00:07:30
let’s say if I write about print and here there
00:07:32
will be some text here, then at the
00:07:34
moment this print belongs to
00:07:36
this condition, if I remove one space, or
00:07:40
rather one indent, at the moment
00:07:42
this print belongs to this
00:07:44
condition, and if I remove another space
00:07:47
one indent, then this print it
00:07:49
in principle, does not belong to any
00:07:51
condition and this print will be
00:07:53
executed one hundred percent,
00:07:55
regardless of whether
00:07:57
any of our conditions are met or not, that is,
00:07:59
here the indentation is most important and of
00:08:02
course these environments, like oh
00:08:05
charmane, immediately tell you where a
00:08:07
certain indentation was missed, where, on the contrary,
00:08:10
too much indentation was indicated,
00:08:12
and so on, well, according to all these
00:08:14
tips you need to follow, you can
00:08:17
say that this is not super convenient with
00:08:18
all these indentations, but I will say that
00:08:20
on the contrary, it is very, very convenient because
00:08:22
in other languages they are used instead of
00:08:24
these double ones instead of: they
00:08:27
use curly braces
00:08:29
like this and they really clutter up the code
00:08:32
because you end up with a lot of
00:08:33
extra extra lines in which
00:08:36
1 curly brace can simply be output,
00:08:37
this all clutters up the code here
00:08:40
in the Python language they simply don’t exist
00:08:42
these curly braces,
00:08:43
instead of them, there is this one: and
00:08:45
just indentations,
00:08:46
so I think this option is much
00:08:48
more comfortable
00:08:50
for reading and writing, you just
00:08:52
need time to get used to all these
00:08:54
indentations here, add another point
00:08:57
regarding checks, now we
00:08:59
have learned to check for not equal to equal
00:09:01
it is greater less more or equal or
00:09:03
less or equal but we
00:09:06
can also check various Boolean
00:09:08
variables, that is, let’s
00:09:09
create a certain variable and let it
00:09:11
also be called, for example, is happy,
00:09:13
that is, is someone happy?
00:09:15
users for example, and as a
00:09:17
value we will specify the value true here,
00:09:19
then I would like to check this change,
00:09:22
let's maybe even create some
00:09:23
new condition,
00:09:24
of course, this could be checked
00:09:26
here here, and we could also
00:09:28
create more wet conditions to check
00:09:29
here, but let's just not we will
00:09:31
pile up the code and create some new
00:09:33
condition in this condition, I would like to
00:09:35
check this variable of ours
00:09:37
is happy, so I will write here that
00:09:39
if is happy it will be equal to
00:09:42
the value true
00:09:43
in this case, let's write about the
00:09:46
fact that user is happy, well, let’s say there
00:09:49
will be us here and the whale will have this text, everything seems to
00:09:52
work correctly, even
00:09:54
let’s run it with you, yes, it
00:09:56
asks you to enter a number and let us
00:09:57
lead, but after entering the number everything
00:09:59
works correctly for us, it turns out that
00:10:01
the user is
00:10:02
he we are happy, everything works correctly,
00:10:04
but at the same time, our
00:10:07
code is not written down quite correctly, the
00:10:09
thing is that this year can be much
00:10:10
shorter and it can be shortened
00:10:13
as follows, we simply remove this
00:10:15
additional check and leave
00:10:17
only the name of the variable, the thing is that
00:10:19
if you just write the name of
00:10:20
the variable here, then it will be a similar
00:10:22
entry to the one we had before,
00:10:25
that is, is happy equals true and simply is
00:10:27
happy
00:10:28
is the same thing, here we also
00:10:30
check for the value true, if at
00:10:32
the moment I run it, then in this
00:10:34
In case of the form here, too, user
00:10:36
is happy, everything will be processed correctly,
00:10:38
also if you need to check the
00:10:40
purpose of the fall, then of course it can be
00:10:42
written in this format, but
00:10:44
again this is a long version and usually
00:10:47
no one writes it like this, it is
00:10:48
usually written as follows, that
00:10:50
is, if us
00:10:51
is happy as if equal to the value of falls give
00:10:54
them this is the word not written in then in this
00:10:56
case we will be executed this piece of
00:10:57
code let me
00:11:00
comment out a little code here just so that it does
00:11:02
n’t bother us anymore so we can
00:11:03
focus on this here a piece
00:11:05
of pieces if now I’ll run it and nothing
00:11:08
additional will be output because
00:11:09
our changes are set to
00:11:11
true, we check the assignments,
00:11:13
so nothing came out at the same time,
00:11:15
if I specify the value false here, then in
00:11:17
this case everything
00:11:19
will be processed correctly in this way
00:11:21
when it comes to various booleans
00:11:24
changes, then there you can simply
00:11:26
write the name of the variable or
00:11:28
add the words not in front of this
00:11:30
variable, thereby you will perform the
00:11:33
correct checks for a certain value,
00:11:35
also let's study additional
00:11:37
operators that exist in conditional
00:11:39
constructions due to the if operator, we
00:11:42
can simply check a certain
00:11:43
condition if the condition turns out to be true,
00:11:45
we execute the code inside this conditional
00:11:48
operator, if it turns out to be false, then we do not
00:11:50
execute the code inside this conditional
00:11:52
operator. In addition to iv, we can also
00:11:55
use an operator such as lc lc, it is
00:11:58
always written at the very end if
00:12:01
we have it only in this case we
00:12:03
we can use lc and it is always
00:12:04
written at the very end, well, lc is an
00:12:08
operator that allows us to execute the
00:12:09
code that will work if the code
00:12:12
in the if statement did not work, well, here we are,
00:12:15
let’s not write something like the
00:12:17
user is an happy, for example, this is
00:12:20
the text and
00:12:21
if I run the program at the moment,
00:12:23
look, we have these conditions, but
00:12:25
it turns out to be true because
00:12:27
it follows the variable with the value true
00:12:28
for this reason, since this condition
00:12:30
turns out to be true, then only
00:12:32
this piece of code is executed and the information is entered
00:12:34
that the user is happy and lc is
00:12:37
simply ignored, at the same time, if I
00:12:40
specify the value fall here, in this case
00:12:42
we get that this condition does
00:12:45
not work for us and in this case the
00:12:48
lc operator works for us, so here we are and it is
00:12:50
usual that the user is not happy
00:12:53
user is an happy that is, the lc operator
00:12:56
can always be used if desired,
00:12:59
it is always used with the if i operator,
00:13:01
it can be used for any if
00:13:03
operator, for example, I could
00:13:06
use it here too, I could
00:13:07
use it for this operator and it
00:13:10
just works at the moment when
00:13:13
we have the if operator itself, it is
00:13:15
incorrect, it does not work for us, and
00:13:18
in addition to the operator and
00:13:19
and also l.n. There is also an
00:13:21
intermediate operator, it is always
00:13:23
written between iv and also between lc,
00:13:26
it is called lc and due to this
00:13:29
operator, you and I can simply
00:13:31
check some additional some
00:13:35
additional condition, and here
00:13:37
we probably would be better off
00:13:39
uncommenting userdata again so that we
00:13:41
can simply what to check here,
00:13:42
let’s say we check
00:13:44
userdata is equal to 5, well, in this spirit,
00:13:46
but if it is equal to 5, then in this
00:13:48
case we will display information
00:13:51
that we have beer is five, for example, let it be
00:13:53
what it will be, provided that we end up with
00:13:56
at the moment I'm
00:13:58
leading let's say the number 5 is like 5
00:14:01
and in this case we are told that
00:14:03
where is five why it worked,
00:14:05
look first 1 1 our conditions it
00:14:09
turned out to be incorrect and because here we
00:14:11
check that if a variable with the
00:14:12
value true then
00:14:14
this piece of code will be executed, this condition turned out to be
00:14:16
incorrect,
00:14:17
so it was ignored, then
00:14:20
we have the following condition in this
00:14:22
condition, we check information from
00:14:24
users if it is equal to 5, in this
00:14:26
case we execute a certain code,
00:14:27
we received a number from the user 5,
00:14:29
so this condition turned out to be true and the
00:14:31
code that was inside here
00:14:33
worked, well, since this
00:14:36
operator worked, then lc it was already
00:14:38
ignored, so the
00:14:41
else and if operator or l.f. this is an operator
00:14:44
that allows us to specify some
00:14:45
additional condition; if this condition
00:14:48
turns out to be true, then in this case the
00:14:50
code inside this condition is executed;
00:14:52
if this condition turns out to be false, but
00:14:54
in our case, for example,
00:14:56
the operator l would work here because
00:14:58
elf did not work, for example, it could also not to
00:15:00
work and then the operator
00:15:03
Elsie and similar lcs would work
00:15:05
and in here there can be as many as you like,
00:15:06
let’s say I can register another
00:15:09
lc here for them here I will already check for
00:15:11
example for the number 7 and if I run this
00:15:14
and let’s see some incorrect number
00:15:16
for example 3 in this case, what we
00:15:18
get is that the first condition turns out to be
00:15:20
false, the second condition turns out to be
00:15:21
false, the third condition also turns out to be
00:15:23
false and there is only one operator left,
00:15:26
this is the lc speaker, which we just brought out
00:15:28
the information that the user is not
00:15:30
happy, by the way, if you want, lc
00:15:33
can be do not use here in this
00:15:35
case, everything will also work correctly,
00:15:37
just if you see some incorrect
00:15:39
value, let’s say there are three,
00:15:41
then in this case all these conditions
00:15:43
will not be incorrect and in general
00:15:45
no code will be processed if you want,
00:15:48
you can use all this without Elsie she
00:15:50
will work correctly
00:15:51
if you need some additional
00:15:53
condition that one hundred percent should
00:15:56
work, then you can still
00:15:57
write another lc, the main thing here is
00:15:59
to follow the structure and we always have
00:16:01
lc at the very top and the background is always
00:16:04
under this keyword if
00:16:07
a lc
00:16:09
by itself it is always at the
00:16:11
very bottom,
00:16:12
this is the design and of
00:16:14
course you can use all of this both
00:16:16
separately and in yourself with whom you can
00:16:18
use without lc
00:16:20
if a you can use without lc well, in
00:16:22
general, all of this can already be combined
00:16:24
as you please,
00:16:25
also if you wish,
00:16:27
you can create any of these conditions and
00:16:29
here you can, for example,
00:16:30
receive data from the user, well, in
00:16:32
principle, here you can already do
00:16:34
absolutely anything you want, but you are
00:16:36
not limited in any way at the moment In each
00:16:38
of the conditions, we always checked only one
00:16:41
variable, here we checked the variable
00:16:43
is happy, here is the user data, and here
00:16:46
also the user data, at the same time, in each
00:16:48
of the conditions, we can check
00:16:50
several variables at once, we can check
00:16:52
several expressions at once, in order for us to
00:16:55
implement this, we must here
00:16:57
to write down certain keywords,
00:16:58
let’s say I want to check
00:17:01
the variable now and let’s fasten it, I want to check
00:17:02
whether it has the value true
00:17:04
and I also want to additionally
00:17:06
check the user variable here,
00:17:08
let’s go ahead and write this right away
00:17:10
and I want to check equal to, well, equal
00:17:14
should the value of this variable be equal to 6
00:17:16
so that I can somehow combine both of these
00:17:19
checks, I need to add a
00:17:20
keyword here if I say that I
00:17:23
want to check that we have
00:17:24
is happy should be equal to the value true
00:17:27
and an additional blow yes it
00:17:29
should be equal to the value 6 that is,
00:17:31
if I say this word and in
00:17:33
this case I need to write the and
00:17:35
operator here, so I seem to be
00:17:38
saying that I must have this condition and this
00:17:41
condition must be true, and only in
00:17:43
this case all the code that is here
00:17:45
it will execute correctly for me
00:17:47
if at the moment I run a program
00:17:49
that looks like the number 6, then we will notice that this
00:17:52
operator generally does not work for us, it does not
00:17:54
work for the reason that
00:17:57
this part of the code, this part of the condition, it
00:17:59
returns the values ​​falls for us
00:18:01
why because well this check
00:18:03
is false so this is why
00:18:06
this part returns false
00:18:07
this is the same part it is correct so
00:18:10
it returns true
00:18:11
but since we have the and operator here it
00:18:12
kind of says that both
00:18:14
this and this part they should return
00:18:16
true and only in this case will we
00:18:18
execute the code that will be
00:18:20
inside for this reason, this didn’t work for me
00:18:23
because the first part
00:18:25
returns a fall, also all the
00:18:28
all so if i statements didn’t work, only
00:18:30
Elsie worked, that’s why it was inferred that
00:18:32
user is in heaven at the same time, if we
00:18:34
here indicate the value true and
00:18:36
let’s say, let’s still
00:18:38
show me some wrong value,
00:18:40
let’s say each of them has a value of 4, then in this
00:18:42
case, again, this condition does not
00:18:43
work because now this part is
00:18:45
correct this part is incorrect, again, that’s why
00:18:51
this whole operator didn’t work for us, and finally, if I still
00:18:53
specify the value here 6 and here the value
00:18:55
corpse, then in this case we are led to user
00:18:57
is happy, this happens for the reason
00:18:59
that we now have this part the conditions are
00:19:01
true, this part of the condition is also true, and
00:19:04
since we need to get it as
00:19:05
if this part was true, but it
00:19:08
did happen for us, for this reason we
00:19:10
enter that the user is happy like
00:19:12
this, here comes like
00:19:13
in addition to the operator and here there
00:19:15
is also another operator or he does
00:19:19
the following: it is important for him that at least one of the parts
00:19:21
is true, in this case, if at
00:19:24
least one of the parts is true and the
00:19:25
conditions as a whole will also be
00:19:27
measured, if I run this now and
00:19:29
let’s say the number is 4, we still have 1,
00:19:33
this one conditional operator it
00:19:34
works correctly because the first
00:19:36
part is true for us until the first
00:19:39
condition is true the second condition
00:19:41
is false
00:19:42
but since you and I must get at
00:19:43
least one of the conditions true and for us it
00:19:46
still happens for this reason we
00:19:48
display all this code that
00:19:50
3 of this api
00:19:51
flock were recorded, and in fact,
00:19:54
you can combine these conditions as much as
00:19:56
you like here now we are checking only
00:19:58
two changes on you can also
00:20:00
add here additionally this
00:20:02
word he some other conditions here
00:20:04
you can write, for example, if 5 is equal to 5
00:20:06
before, you can also add one more condition,
00:20:08
but in general, here you can
00:20:10
add as many similar
00:20:11
conditions as you like, all this will be processed
00:20:13
correctly and simply in one conditional
00:20:15
statement you will immediately have
00:20:16
many different checks, well,
00:20:18
Finally, let's look at the
00:20:19
work of the ternary operator. The ternary
00:20:22
operator is essentially the same flc
00:20:24
only in an abbreviated format so that we can
00:20:27
consider it. Let's first
00:20:29
indicate some changes in this
00:20:31
change. We will receive information from
00:20:33
users; we
00:20:35
will not display any text to them. Well, here initially
00:20:37
we will write a complete construction, as it were, and
00:20:39
a little later we will use the
00:20:41
ternary operator
00:20:42
and consider the number of well, the difference in the
00:20:44
number of lines of code, here we will
00:20:46
write a super and some simple condition,
00:20:48
for example, if I receive the string five from the user,
00:20:50
then in this case into a
00:20:52
variable number I will set
00:20:54
the value to 5, otherwise I’ll assume you
00:20:57
set the variable number to
00:20:58
0, and at the very end I
00:21:01
will simply display this change on the screen. If
00:21:04
you run this at the moment, then
00:21:06
first of all you need to display it,
00:21:07
let’s say I drive 4 and here we have it
00:21:09
the value is 0, that is, everything was processed
00:21:11
correctly, I did not enter the line as I entered it, not
00:21:14
five, so we had the
00:21:16
value set to 0, but if I still
00:21:19
run it again, I mean here the line five, then in
00:21:21
this case the value 5 will be set
00:21:22
to this variable, well, this variable at the
00:21:24
end we display this, in principle,
00:21:26
now we have implemented it as if without
00:21:28
using the ternary operator,
00:21:29
now let's try to use the
00:21:31
ternary operator for this we will write
00:21:34
the following, we seem to be saying that we are
00:21:36
creating a certain variable nam and in this
00:21:38
variable we will set
00:21:39
We will set the next ones to the
00:21:41
value 5 only if
00:21:45
our date is equal to a string like
00:21:48
five, otherwise you and I will set
00:21:50
the number 0 here. Well, in fact,
00:21:53
now I can comment out everything and if I
00:21:55
run this now,
00:21:56
we will notice with you the next one, if
00:21:58
God's five is here, then in this case
00:22:00
the five is set here, as it were, and
00:22:02
then it is output
00:22:03
if, like
00:22:04
any value, it will be set to
00:22:06
the value, well, this change will be
00:22:08
set to 0, so the
00:22:10
ternary operator is essentially the
00:22:12
same flc just it is written down in one
00:22:15
line, here we seem to be saying that we
00:22:17
are setting a certain value if
00:22:19
this condition is true if
00:22:21
this condition is not true
00:22:23
then we set some other
00:22:24
value, so
00:22:25
in general, all similar pernod rn
00:22:27
and and operators are very it is convenient to use
00:22:29
when we have a certain conditional operator
00:22:31
that consists exclusively of
00:22:33
iv and also of lc in this case
00:22:36
it can be very easily converted to one
00:22:37
line as was done in this
00:22:39
example, well, this is where our lesson
00:22:41
comes to an end during this lesson you and I
00:22:43
have learned to work with conditional
00:22:45
operators in the Python language, and in the future
00:22:47
we will resort to conditional
00:22:49
constructions more than once, so if there is something you
00:22:51
haven’t learned yet, don’t
00:22:53
worry, because a little later we
00:22:55
will be covering all of this more than once resort
00:22:57
to the same thing, I hope you liked the lesson,
00:22:59
if so, don’t forget
00:23:01
to subscribe to the channel and join our
00:23:03
social networks, all links to them will be in
00:23:04
the description of this video, that’s
00:23:06
all, I ’ll see you in the future, see you soon

Description:

Условные конструкции предоставляют возможность выполнить проверку условия и в зависимости от результата выполнить определенный участок кода. За урок мы научимся использовать if-else, а также тернарный оператор в языке Python. ✅ Полезные ссылки: – Урок на сайте itProger: https://itproger.com/course/python/5 ⏰ Тайм коды: 00:00 - Начало 00:16 - Что такое условные конструкции? 00:40 - Создание простого условия 03:00 - Проверка данных от пользователя 04:27 - Форматы проверок 05:33 - Вложенные условия 08:57 - Проверка булевых переменных 11:36 - Оператор «else» 13:18 - Оператор «elif» 16:38 - Несколько условий 20:18 - Тернарный оператор 22:40 - Заключительная часть ✔ Сообщество программистов: https://itproger.com/ ✔ ------------- Вступай в группу Вк - https://vk.com/prog_life 🚀 Инстаграм itProger: https://www.instagram.com/itproger_official/ Группа FaceBook - https://goo.gl/XW0aaP Instagram: https://www.instagram.com/gosha_dudar/ Telegram: http://t.me/itProger_official Twitter - https://twitter.com/GoshaDudar - Уроки от #itProger 👨🏼‍💻 - Все уроки по хештегу #itprogerLessons

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Уроки Python с нуля / #5 – Условные операторы" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Уроки Python с нуля / #5 – Условные операторы" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Уроки Python с нуля / #5 – Условные операторы" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Уроки Python с нуля / #5 – Условные операторы" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Уроки Python с нуля / #5 – Условные операторы"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Уроки Python с нуля / #5 – Условные операторы"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.