Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,060 --> 00:00:05,020
It's time to talk about another topic that sounds a lot more confusing.
2
00:00:05,020 --> 00:00:07,550
Short circuiting than it actually is.
3
00:00:07,570 --> 00:00:13,010
It's quite simple short circuiting looks something like this.
4
00:00:13,030 --> 00:00:20,470
Remember when I taught you the word and so we can use let's say for example is friend
5
00:00:23,240 --> 00:00:37,030
equals too true and let's say is user is equal to true and I can do an expression here saying is friend
6
00:00:37,480 --> 00:00:43,530
and is user now in here.
7
00:00:43,550 --> 00:00:54,000
When we run this let's printed here just so we can see if I run this I get true because both of these
8
00:00:54,060 --> 00:01:05,560
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.
9
00:01:05,580 --> 00:01:09,790
Best friends forever now.
10
00:01:09,860 --> 00:01:19,070
Short circuiting can be done when we use something like for which we haven't seen before but again you
11
00:01:19,070 --> 00:01:23,080
can see here that it's highlighted in blue so it is a keyword.
12
00:01:23,180 --> 00:01:32,660
A python keyword now or says if either one of these conditions are true then run this piece of code.
13
00:01:32,800 --> 00:01:36,080
So if I run this I get.
14
00:01:36,280 --> 00:01:38,800
Best friends forever.
15
00:01:38,830 --> 00:01:40,090
Now let me ask you this.
16
00:01:40,180 --> 00:01:43,270
Which operation do you think is more performance.
17
00:01:43,270 --> 00:01:46,150
The or or the end.
18
00:01:46,150 --> 00:01:47,970
Is there a difference.
19
00:01:48,250 --> 00:01:51,790
As a matter of fact there is because of short circuiting.
20
00:01:52,030 --> 00:02:01,020
You see when I do or here because I only care if either one of these is true the Python interpreter
21
00:02:01,020 --> 00:02:09,480
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
22
00:02:09,480 --> 00:02:14,610
it's going to see the word or and it's going to say hey I don't care what this is.
23
00:02:14,610 --> 00:02:19,150
Maybe this is a really heavy operation or something that I need to look up.
24
00:02:19,200 --> 00:02:25,910
Well I don't really care because this is already true whether this is true or this is false.
25
00:02:25,980 --> 00:02:31,840
I don't really care because either way I'm going to have to print this as you can see it still prints.
26
00:02:31,860 --> 00:02:39,710
Best friends forever so short circuiting happens when the interpreter is smart enough to say I already
27
00:02:39,710 --> 00:02:40,990
did enough work.
28
00:02:41,060 --> 00:02:44,020
I don't care what this is this is just wasted work if I do it.
29
00:02:44,050 --> 00:02:50,240
So I'm going to short circuit and say hey I'm going to just ignore this and I'm going to start printing
30
00:02:51,080 --> 00:02:57,290
so using or is a little bit more efficient but again it depends on what you need.
31
00:02:57,290 --> 00:03:06,330
If you need to check if both is friend and is user true you'll have to use and but this works both ways
32
00:03:06,330 --> 00:03:07,970
with and as well.
33
00:03:07,980 --> 00:03:16,230
For example if its friend is false this is going to get short circuited because I'm going to say hey
34
00:03:16,530 --> 00:03:19,890
if his friend is false.
35
00:03:19,890 --> 00:03:24,780
Well I don't really care what is user is because there's no way that both of these are true.
36
00:03:24,780 --> 00:03:30,590
I've already seen that one of them is false so I'm going to ignore this and I'm going to print this.
37
00:03:30,830 --> 00:03:35,730
And when I say I I mean our good ole friend Python interpreter.
38
00:03:35,860 --> 00:03:42,970
Now this topic of short circuiting doesn't really get taught in beginner Python courses but now if you
39
00:03:42,970 --> 00:03:50,080
hear this maybe hear this in an interview as you can see it sounds a lot more difficult than it actually
40
00:03:50,080 --> 00:03:50,340
is.
41
00:03:50,440 --> 00:03:53,830
And frankly it makes a lot of sense right.
42
00:03:53,830 --> 00:04:00,400
We want our machines to be efficient and it is quite efficient due to short circuiting I'll see in the
43
00:04:00,400 --> 00:04:01,370
next one.
44
00:04:01,430 --> 00:04:01,690
Bobby.
4577
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.