1 00:00:00,450 --> 00:00:01,290 Welcome back. 2 00:00:01,980 --> 00:00:09,480 Let's talk about a important term when it comes to programming, and that is operator precedence. 3 00:00:11,350 --> 00:00:12,790 Now, what does that mean? 4 00:00:13,090 --> 00:00:17,170 Again, we're using our knowledge from math class. 5 00:00:17,470 --> 00:00:28,540 It's the idea that if I do 20 plus three times four, it means that different operators have precedence 6 00:00:28,540 --> 00:00:29,770 over different ones. 7 00:00:30,430 --> 00:00:37,780 That is, we multiply this first equals to 12 and then 20 gets added to 12. 8 00:00:38,810 --> 00:00:44,030 Because the Python interpreter is going to follow a basic set of rules. 9 00:00:44,870 --> 00:00:48,350 For example, if I do 20 minus three here. 10 00:00:49,740 --> 00:00:51,360 And let's print this out. 11 00:00:53,490 --> 00:00:54,300 Click Run. 12 00:00:56,340 --> 00:01:04,590 I get eight because three times four gets evaluated first, which equals to 12, and then subtract it 13 00:01:04,590 --> 00:01:05,670 from 20. 14 00:01:06,120 --> 00:01:11,310 It's not that this goes first and then we multiply 17 by four. 15 00:01:12,080 --> 00:01:15,170 And this operator precedence shouldn't be new, right? 16 00:01:15,170 --> 00:01:17,400 If you've taken any sort of math class. 17 00:01:17,420 --> 00:01:21,140 You understand that this is how well math works. 18 00:01:21,440 --> 00:01:24,580 And this works the same in all programming languages. 19 00:01:24,590 --> 00:01:27,050 So the order is this. 20 00:01:27,560 --> 00:01:30,050 First we follow the brackets. 21 00:01:30,050 --> 00:01:33,050 So whatever is wrapped in a bracket, we do first. 22 00:01:33,440 --> 00:01:37,640 The second is we do the power of. 23 00:01:38,000 --> 00:01:43,350 So whatever is done in the power of will be after parentheses. 24 00:01:43,370 --> 00:01:47,510 For example, if I do parentheses here. 25 00:01:48,910 --> 00:01:56,920 And then to the power of, let's say two or let's do plus two to the power of two. 26 00:01:57,370 --> 00:02:05,710 Well, the first operation that will happen is 20 minus three, because that's the first precedence. 27 00:02:05,890 --> 00:02:10,600 And then we do two to the power of two, because that's the next precedence. 28 00:02:12,240 --> 00:02:16,120 And then only after we do that, we add these two together. 29 00:02:16,140 --> 00:02:17,280 If I click Run. 30 00:02:18,590 --> 00:02:21,440 I get 21, which again makes sense. 31 00:02:21,440 --> 00:02:24,080 17 plus four. 32 00:02:26,200 --> 00:02:32,590 After the power of we have the multiplication and division. 33 00:02:33,460 --> 00:02:38,890 And then finally, the last precedence is addition and subtraction. 34 00:02:39,870 --> 00:02:42,510 Now, this isn't going to be a math class. 35 00:02:42,540 --> 00:02:44,390 Some people really love math. 36 00:02:44,400 --> 00:02:46,320 Some people really don't. 37 00:02:46,530 --> 00:02:52,490 But I want to just give you this basic understanding of operator precedence when you see it. 38 00:02:52,500 --> 00:02:55,350 We'll do some exercises here to get accustomed to it. 39 00:02:55,350 --> 00:02:59,430 But trust me, this is as mathy as we're going to get in this course. 40 00:02:59,700 --> 00:03:03,210 The math part of the course is, well, just here. 41 00:03:03,390 --> 00:03:07,500 It's going to get a lot more interesting as we learn about different data types. 42 00:03:07,950 --> 00:03:09,060 I'll see you in the next one. 43 00:03:09,450 --> 00:03:09,990 Bye bye.