1 00:00:00,000 --> 00:00:03,727 [MUSIC] 2 00:00:03,727 --> 00:00:08,908 So, hopefully this gets you started with Python, the programming language 3 00:00:08,908 --> 00:00:13,700 with the iPython Notebook, and a little bit of iterating the console. 4 00:00:13,700 --> 00:00:17,560 We're gonna be using this console again and again, it's really a fun, 5 00:00:17,560 --> 00:00:21,230 simple way to manage and interact with data. 6 00:00:21,230 --> 00:00:24,430 And there's also tools for visualizing, for navigating, for 7 00:00:24,430 --> 00:00:27,150 doing machine learning in this Python space. 8 00:00:27,150 --> 00:00:30,240 So, it's really a great programming language for us. 9 00:00:30,240 --> 00:00:33,590 And, in fact, there's been a lot of surveys 10 00:00:33,590 --> 00:00:38,510 that say most recently Python is the programming language for data science and 11 00:00:38,510 --> 00:00:40,759 that's why we picked it for this course. 12 00:00:42,200 --> 00:00:46,270 As a final step, let's talk about creating functions in Python. 13 00:00:46,270 --> 00:00:50,600 It's actually pretty easy to create a wide range of functions within Python and 14 00:00:50,600 --> 00:00:51,700 it's pretty natural. 15 00:00:51,700 --> 00:00:53,230 So there's two ways of doing it. 16 00:00:53,230 --> 00:00:55,610 So let's go ahead and get started. 17 00:00:55,610 --> 00:01:00,967 So, again ask m for a text box and 18 00:01:00,967 --> 00:01:04,938 we're gonna talk about 19 00:01:04,938 --> 00:01:10,308 creating functions in Python. 20 00:01:10,308 --> 00:01:16,490 Okay, so the first way is using the def command. 21 00:01:16,490 --> 00:01:21,369 So this is defining a function, let's say a fun function, 22 00:01:21,369 --> 00:01:25,770 add 2 which takes an element x and adds 2 to it. 23 00:01:25,770 --> 00:01:29,910 So we write def add2, and in parenthesis, you put the number of parameters you have, 24 00:01:29,910 --> 00:01:32,280 there is this x, you could have x, y, z, and so on. 25 00:01:32,280 --> 00:01:34,190 And then you put a colon at the end. 26 00:01:35,550 --> 00:01:39,625 And just like with flukes, we want to align in vertically, 27 00:01:39,625 --> 00:01:44,450 kinda tabulated, until we've written out all the function we want to do. 28 00:01:44,450 --> 00:01:50,210 So for example, we could say y is equal to x 29 00:01:50,210 --> 00:01:54,960 plus 2, and then we say return y. 30 00:01:56,040 --> 00:01:59,190 So here we defined a function add 2. 31 00:01:59,190 --> 00:02:02,740 So let's, remember integer value i, let's just set it to some number, 32 00:02:02,740 --> 00:02:07,995 let's say we say that i is equal to 5, and we say 33 00:02:07,995 --> 00:02:14,790 add 2 with the input i and we get 7. 34 00:02:14,790 --> 00:02:15,290 Voila. 35 00:02:16,770 --> 00:02:21,030 The second way to define functions is using what Python calls lambda's, and 36 00:02:21,030 --> 00:02:24,600 these are for simple functions and it's useful to know it. 37 00:02:24,600 --> 00:02:29,770 It's used in a variety of places where you just do a simple transformation, 38 00:02:29,770 --> 00:02:32,680 even add to is a simple transformation so for example, 39 00:02:32,680 --> 00:02:37,820 let's create a function called square. 40 00:02:40,430 --> 00:02:44,778 So this is the square function, 41 00:02:44,778 --> 00:02:53,350 which is a lambda that takes into input x and returns x times x. 42 00:02:53,350 --> 00:02:57,500 So if I read this to you when defining a function, this land is a function, 43 00:02:57,500 --> 00:03:01,680 takes x's input and returns x times x. 44 00:03:01,680 --> 00:03:03,850 That's what it tells us after the column. 45 00:03:03,850 --> 00:03:07,300 So we defined that and now we can apply square to anything we want, so 46 00:03:07,300 --> 00:03:08,280 for example. 47 00:03:08,280 --> 00:03:14,370 If we say what is the square of 3, it should say 9 and 48 00:03:14,370 --> 00:03:17,590 there we go, two ways to define functions in Python. 49 00:03:18,610 --> 00:03:23,054 Now we have the grasps of Python's basics, they can used for 50 00:03:23,054 --> 00:03:27,949 all assignments we're gonna be building up in this first course. 51 00:03:27,949 --> 00:03:31,879 [MUSIC]