1 00:00:00,000 --> 00:00:03,660 There are lots of different ways to run your Python code, 2 00:00:03,900 --> 00:00:07,650 but when you get into an actual job, you're going to be using 3 00:00:07,650 --> 00:00:10,200 your command line more than anything else. 4 00:00:10,200 --> 00:00:13,300 And so in this course, we're actually going to look over two different ways. 5 00:00:13,360 --> 00:00:16,590 We're going to go over rather two different ways of running 6 00:00:16,590 --> 00:00:17,500 your Python code. 7 00:00:17,500 --> 00:00:20,300 The first one is the command line, which I really want you 8 00:00:20,380 --> 00:00:22,930 to get familiar with just at the very beginning. 9 00:00:22,940 --> 00:00:25,540 And the second way is using a Jupiter Notebook, which we'll 10 00:00:25,550 --> 00:00:26,620 cover in a different lesson. 11 00:00:26,720 --> 00:00:29,660 But for now, what I would like you to do is open up your 12 00:00:29,670 --> 00:00:32,820 terminal or your command line program. 13 00:00:32,970 --> 00:00:34,200 For me, it's called Terminal. 14 00:00:34,210 --> 00:00:37,020 If you're on Windows, that's probably - 'cmd', 'cmder', or 15 00:00:37,540 --> 00:00:42,220 PowerShell. And if you are on Linux, it's probably like Bash 16 00:00:42,230 --> 00:00:45,530 or some custom terminal that you've downloaded on your own. 17 00:00:45,890 --> 00:00:48,820 And let's go ahead and type 'python -V', 18 00:00:49,400 --> 00:00:52,400 and that's going to show us the current version of Python we're working with. 19 00:00:52,480 --> 00:00:56,380 We can also type 'which python', and it will show us exactly 20 00:00:56,380 --> 00:01:00,500 where the Python program is being called upon. 21 00:01:00,500 --> 00:01:01,900 Now that's actually not super important. 22 00:01:01,900 --> 00:01:05,000 Mines going to say 'pyenv/shims' because I'm using 'pyenv', 23 00:01:05,000 --> 00:01:06,800 yours might say something totally different. 24 00:01:06,819 --> 00:01:11,260 But regardless, it will say something. That's not actually 25 00:01:11,270 --> 00:01:12,460 writing any Python code. 26 00:01:12,470 --> 00:01:16,160 That's actually just figuring out where Python is installed 27 00:01:16,170 --> 00:01:19,830 on our computer and showing us the version. To get into Python, 28 00:01:19,840 --> 00:01:22,560 our Python shell, where we can actually write Python, 29 00:01:22,680 --> 00:01:24,660 just type the word 'python', and hit 'Enter'. 30 00:01:24,880 --> 00:01:30,040 And here we can see that I'm using Python 3.7.2. 31 00:01:30,200 --> 00:01:33,500 I think this is when I set the 'default'. 32 00:01:33,500 --> 00:01:37,000 I'm not entirely sure why that is so far behind, to be totally 33 00:01:37,100 --> 00:01:40,450 honest, but there's a little help in here as well. 34 00:01:40,460 --> 00:01:41,440 So "Type "help", 35 00:01:41,500 --> 00:01:42,880 "copyright", "credits", or "license" 36 00:01:42,890 --> 00:01:44,290 for more information". Let's type 'help'. 37 00:01:45,800 --> 00:01:49,200 Okay. "Type 'help() for interactive help or help( 38 00:01:49,340 --> 00:01:52,550 object) for help about object". 39 00:01:52,550 --> 00:01:53,900 We don't know about objects yet, 40 00:01:53,900 --> 00:01:55,100 so let's just keep this simple and 41 00:01:55,100 --> 00:01:59,800 type 'help()', and it gives us a bunch of information in here. 42 00:01:59,880 --> 00:02:00,960 This is kind of cool. 43 00:02:00,960 --> 00:02:05,500 "Welcome to Python 3.7's help utility!". "To get a list of available 44 00:02:05,500 --> 00:02:08,500 modules, keywords, symbols, or topics, type "modules", "keywords", 45 00:02:08,500 --> 00:02:10,100 "symbols", or "topics". So let's type 'modules'. 46 00:02:10,199 --> 00:02:12,660 Now, we aren't going to learn what all these are right away. 47 00:02:12,880 --> 00:02:15,550 This is just sort of exploring the command line a little bit. 48 00:02:15,560 --> 00:02:17,920 And so that showed me some stuff. That's kind of cool, 49 00:02:18,080 --> 00:02:19,760 but I want to get out of here. 50 00:02:19,770 --> 00:02:22,280 So let's type 'quit'. Did nothing, 51 00:02:22,340 --> 00:02:25,010 or so it seems it did nothing. 52 00:02:25,200 --> 00:02:29,300 What I actually did was get rid of the 'help' tool that we were inside of. 53 00:02:29,300 --> 00:02:31,800 So we are technically inside of a program in our command 54 00:02:31,870 --> 00:02:35,190 line. Now, 'help' is a super useful function when you're just 55 00:02:35,200 --> 00:02:36,200 learning Python. 56 00:02:36,210 --> 00:02:39,870 But to be totally honest, it is not super fun. 57 00:02:39,880 --> 00:02:43,170 I can't run 'clear' because I'm not actually on my command 58 00:02:43,180 --> 00:02:44,790 line. I'm actually inside of Python. 59 00:02:46,500 --> 00:02:48,800 So I'm going to clear up some of the stuff. 60 00:02:48,900 --> 00:02:53,160 And to write your first Python script is incredibly simple. 61 00:02:53,400 --> 00:02:58,160 So type the word 'print', with a parentheses, an opening parentheses; 62 00:02:59,500 --> 00:03:01,400 use a quotation mark, and say 63 00:03:01,400 --> 00:03:03,500 [no audio] 64 00:03:03,500 --> 00:03:06,400 "Hello World", end it with another quotation mark. 65 00:03:06,400 --> 00:03:10,230 We've got an opening one right here, and we have, sorry, we 66 00:03:10,230 --> 00:03:14,700 have an opening one right here, and we have a closing one over here. 67 00:03:14,710 --> 00:03:15,930 Same thing with parentheses, 68 00:03:15,930 --> 00:03:18,580 we have one here, and we have one here. 69 00:03:18,590 --> 00:03:19,780 Go ahead, hit 70 00:03:19,790 --> 00:03:21,530 'Enter'. It says "Hello World!". 71 00:03:21,540 --> 00:03:24,920 And just like that, if you have followed that along on your 72 00:03:24,930 --> 00:03:26,780 computer, you have actually written Python. 73 00:03:26,840 --> 00:03:27,950 It's literally that easy. 74 00:03:28,900 --> 00:03:31,800 So right now we are inside of our Python interactive shell. 75 00:03:31,820 --> 00:03:34,870 We can do all sorts of Python stuff in here, and we're 76 00:03:34,870 --> 00:03:36,800 going to be using this and Jupyter Notebook throughout 77 00:03:36,800 --> 00:03:37,800 the rest of the course as well. 78 00:03:37,920 --> 00:03:41,370 Now to get rid of this, to get outside of this, because currently 79 00:03:41,380 --> 00:03:43,260 we're stuck in like a Python program, 80 00:03:43,420 --> 00:03:47,220 just type 'quit' with opening and closing parentheses, and 81 00:03:47,230 --> 00:03:49,350 you'll get outside of your Python program. 82 00:03:50,200 --> 00:03:53,100 And to get back in, simply just type 'python'. 83 00:03:54,500 --> 00:03:58,400 'quit()'. And if you are one of the unlucky people who has to type 84 00:03:58,440 --> 00:04:03,100 'python3' in order to see the Python 3 program actually 85 00:04:03,110 --> 00:04:05,800 execute on your computer, you simply just type 'python3', 86 00:04:05,800 --> 00:04:08,300 and that will go into your Python 3 shell. 87 00:04:08,300 --> 00:04:10,400 You can actually see for me that changed my version of Python 88 00:04:10,490 --> 00:04:12,200 as well to Python 3.8. 89 00:04:12,200 --> 00:04:13,900 And same thing, 'quit()'. 90 00:04:14,800 --> 00:04:18,600 Now, last thing to note is Python files are usually stored 91 00:04:18,600 --> 00:04:22,800 in some sort of 'python file.py' file. 92 00:04:23,519 --> 00:04:25,170 '.py' is the extension here. 93 00:04:25,180 --> 00:04:26,250 That's the important part. 94 00:04:26,459 --> 00:04:29,700 And to run your Python file is simply just running 'python', 95 00:04:29,700 --> 00:04:30,750 and then the file name. 96 00:04:31,040 --> 00:04:34,160 And so this is getting into command line stuff again, because 97 00:04:34,170 --> 00:04:35,810 this is the program you want to call. 98 00:04:35,900 --> 00:04:40,380 And this is the first argument. You're saying, "Hey, run Python. 99 00:04:40,590 --> 00:04:42,150 But don't just give me the shell, 100 00:04:42,380 --> 00:04:43,820 actually run this file". 101 00:04:43,830 --> 00:04:45,080 Now, this file doesn't exist. 102 00:04:45,090 --> 00:04:47,600 We'll get into that a little bit later. But that is how you 103 00:04:47,610 --> 00:04:49,630 would run a Python file. 104 00:04:49,720 --> 00:04:52,870 One last thing to keep in mind, again we'll talk about this 105 00:04:52,960 --> 00:04:56,590 much more down the road, is Python is case sensitive, and 106 00:04:57,000 --> 00:04:59,460 it's also indentation sensitive. 107 00:04:59,470 --> 00:05:02,160 So we don't use things like curly braces like you see in 108 00:05:02,170 --> 00:05:05,880 JavaScript, or PHP, or in a lot of different languages. 109 00:05:05,890 --> 00:05:09,180 We don't really use curly braces too much in Python. 110 00:05:09,180 --> 00:05:10,800 Instead, we use indentation. 111 00:05:10,800 --> 00:05:14,500 Makes our code nice and easy to read, makes it nice and easy to debug. 112 00:05:14,560 --> 00:05:17,590 And honestly, a lot of people really love the fact that it 113 00:05:17,600 --> 00:05:20,500 uses indentation rather than curly braces. I love it. 114 00:05:20,540 --> 00:05:23,500 I thought it was weird at first, but I actually love it now. 115 00:05:23,510 --> 00:05:26,140 And it is so much better than writing curly braces everywhere. 116 00:05:26,280 --> 00:05:29,220 So what I would like you to do is open up your command line 117 00:05:29,220 --> 00:05:32,900 program, type in 'python', type in 'print( 118 00:05:32,980 --> 00:05:34,150 "Hello World!")' 119 00:05:34,160 --> 00:05:36,690 just like I did, hit 'Enter', 120 00:05:36,700 --> 00:05:38,190 and you'll see "Hello World!", 121 00:05:38,380 --> 00:05:39,820 then 'quit()'. 122 00:05:39,940 --> 00:05:43,030 Once you've done that, you've successfully written some Python, 123 00:05:43,030 --> 00:05:45,333 and it's time to move on to the next lesson.