1 00:00:00,810 --> 00:00:01,980 - [Instructor] As we've discussed, 2 00:00:01,980 --> 00:00:04,090 there are quite a number of libraries 3 00:00:04,090 --> 00:00:05,850 available to you as part of 4 00:00:05,850 --> 00:00:08,360 the Python standard library. 5 00:00:08,360 --> 00:00:10,770 In this video, I just wanna take a brief look 6 00:00:10,770 --> 00:00:15,140 at the math module within the Python standard library 7 00:00:15,140 --> 00:00:19,650 which contains many common mathematical functions. 8 00:00:19,650 --> 00:00:21,360 In order to use those functions, 9 00:00:21,360 --> 00:00:24,003 you will need to import the math library. 10 00:00:25,150 --> 00:00:27,240 You may recall that I've demonstrated 11 00:00:27,240 --> 00:00:29,270 some tab completion capabilities, 12 00:00:29,270 --> 00:00:32,980 so if you want to see what's in the math library, 13 00:00:32,980 --> 00:00:35,860 you can now type math dot and hit Tab, 14 00:00:35,860 --> 00:00:39,540 and now you can see all of these different functions 15 00:00:39,540 --> 00:00:42,710 and a couple of variables; 16 00:00:42,710 --> 00:00:46,363 e, pi, nan, tau. 17 00:00:47,220 --> 00:00:50,770 Each of these are technically constants 18 00:00:50,770 --> 00:00:52,150 that you can use in your code, 19 00:00:52,150 --> 00:00:54,810 but in Python, we don't actually have 20 00:00:54,810 --> 00:00:57,370 true constant data, 21 00:00:57,370 --> 00:01:00,150 which means you could accidentally modify 22 00:01:00,150 --> 00:01:02,320 the variables that are pre-defined 23 00:01:02,320 --> 00:01:03,830 in the math module 24 00:01:03,830 --> 00:01:06,710 if you assign a new value to them. 25 00:01:06,710 --> 00:01:08,470 So you do wanna be careful 26 00:01:08,470 --> 00:01:12,080 not to accidentally overwrite those variables 27 00:01:12,080 --> 00:01:15,760 once you import them into your code. 28 00:01:15,760 --> 00:01:18,070 As you can see here, there's a whole bunch 29 00:01:18,070 --> 00:01:20,610 of functions available for your use. 30 00:01:20,610 --> 00:01:22,540 Let's say you don't know 31 00:01:22,540 --> 00:01:24,180 how to use a particular function 32 00:01:24,180 --> 00:01:25,970 and you wanna learn more about it. 33 00:01:25,970 --> 00:01:27,730 You can type the name of the function 34 00:01:27,730 --> 00:01:30,580 and a question mark, and once again, 35 00:01:30,580 --> 00:01:33,460 it will give you some documentation 36 00:01:33,460 --> 00:01:36,360 about that particular function. 37 00:01:36,360 --> 00:01:38,540 For instance, if I wanna go ahead 38 00:01:38,540 --> 00:01:42,850 and calculate the square root of a value, 39 00:01:42,850 --> 00:01:45,450 let's say we wanna do the square root of 900, 40 00:01:45,450 --> 00:01:49,520 you can see quickly that the square root of 900 is 30. 41 00:01:49,520 --> 00:01:52,810 Similarly, let's say we wanted to calculate 42 00:01:52,810 --> 00:01:56,190 the absolute value of a negative number. 43 00:01:56,190 --> 00:01:57,820 We could use FABS, 44 00:01:57,820 --> 00:02:00,150 which is floating point absolute value, 45 00:02:00,150 --> 00:02:02,160 and you can see that it gives you back 46 00:02:02,160 --> 00:02:06,920 the positive result of calling that function. 47 00:02:06,920 --> 00:02:09,120 Again, if you have any use 48 00:02:09,120 --> 00:02:12,410 for basic mathematical functionality, 49 00:02:12,410 --> 00:02:14,170 you'll definitely want to take a look 50 00:02:14,170 --> 00:02:15,990 at the math library. 51 00:02:15,990 --> 00:02:18,590 Similarly, in the online documentation 52 00:02:18,590 --> 00:02:20,380 that I've shown you a couple of times now 53 00:02:20,380 --> 00:02:24,130 at python.org, you will definitely want to go back 54 00:02:24,130 --> 00:02:27,450 once again and take a look at that master list 55 00:02:27,450 --> 00:02:29,730 of all the different modules that are built-in 56 00:02:29,730 --> 00:02:32,140 to the Python standard library for you 57 00:02:32,140 --> 00:02:34,820 so that you can get a sense of the categories 58 00:02:34,820 --> 00:02:37,450 of functionality that are available. 59 00:02:37,450 --> 00:02:39,890 Eventually, you'll probably want to dive into 60 00:02:39,890 --> 00:02:41,580 a number of those libraries 61 00:02:41,580 --> 00:02:44,880 to see what pre-existing capabilities they give you. 62 00:02:44,880 --> 00:02:46,550 In Python, they take 63 00:02:46,550 --> 00:02:49,030 the everything but the kitchen sink approach 64 00:02:49,030 --> 00:02:51,730 where they include as much as possible 65 00:02:51,730 --> 00:02:54,240 so that you can focus on the logic 66 00:02:54,240 --> 00:02:55,880 of what you need to get done 67 00:02:55,880 --> 00:02:58,400 as opposed to the low-level details 68 00:02:58,400 --> 00:03:01,320 of how to perform everyday tasks 69 00:03:01,320 --> 00:03:04,030 that lots of Python programmers have performed 70 00:03:04,030 --> 00:03:05,030 in the past. 71 00:03:05,030 --> 00:03:08,140 That's just with the Python standard library. 72 00:03:08,140 --> 00:03:11,950 That doesn't include the thousands of other libraries 73 00:03:11,950 --> 00:03:13,380 that are available to you, 74 00:03:13,380 --> 00:03:15,740 most of which are open source. 75 00:03:15,740 --> 00:03:19,797 You can access many of them on sites like github.com.