WEBVTT 1 00:00:00.110 --> 00:00:01.830 line:15% Hi and welcome back. 2 00:00:01.830 --> 00:00:03.280 line:15% In this video, we're going to be running 3 00:00:03.280 --> 00:00:05.180 line:15% a couple of things in the terminal, 4 00:00:05.180 --> 00:00:07.080 just to show you how it goes. 5 00:00:08.510 --> 00:00:09.980 What we looked at in the last video 6 00:00:09.980 --> 00:00:13.700 is that if you have Python in your path, 7 00:00:13.700 --> 00:00:16.950 you should be able to launch the terminal app on Mac, 8 00:00:16.950 --> 00:00:21.500 terminal on Linux, or CMD.exe on Windows 9 00:00:21.500 --> 00:00:23.970 in order to open up Python. 10 00:00:23.970 --> 00:00:26.170 So let's do just that, I'm gonna type Python 11 00:00:27.060 --> 00:00:28.890 and then press Enter, and as you can see, 12 00:00:28.890 --> 00:00:33.200 I get Python 2.7 because that's the default on Mac. 13 00:00:34.440 --> 00:00:38.950 Here we've got our Python interactive interpreter. 14 00:00:38.950 --> 00:00:40.610 Python comes with this programme, 15 00:00:40.610 --> 00:00:42.180 and essentially when you run it, 16 00:00:42.180 --> 00:00:45.130 it just opens up an interpreter in Python 17 00:00:45.130 --> 00:00:47.300 that you can type Python commands into, 18 00:00:47.300 --> 00:00:50.180 and it will execute them immediately. 19 00:00:50.180 --> 00:00:53.650 So you can type something like print hello world, 20 00:00:54.490 --> 00:00:56.350 and it'll print it out to you. 21 00:00:56.350 --> 00:00:58.200 You can define functions 22 00:01:00.530 --> 00:01:02.630 and then as soon as you type the code wrong, 23 00:01:02.630 --> 00:01:04.760 this realises that you're typing 24 00:01:04.760 --> 00:01:06.980 a more complex command, and it gives you a new line 25 00:01:06.980 --> 00:01:09.210 where you can type, make sure to press Tab 26 00:01:09.210 --> 00:01:11.370 at this point to add the spacing 27 00:01:11.370 --> 00:01:13.570 that the function needs, you know that functions 28 00:01:13.570 --> 00:01:15.710 need to be indented more at the beginning. 29 00:01:17.230 --> 00:01:18.840 Inside the block, and then you can 30 00:01:18.840 --> 00:01:20.910 type Enter twice in order to execute the function, 31 00:01:20.910 --> 00:01:25.740 then you can run the function and it will return the result. 32 00:01:25.740 --> 00:01:27.490 This is pretty powerful, having an 33 00:01:27.490 --> 00:01:29.720 interactive interpreter like this. 34 00:01:29.720 --> 00:01:31.870 As you are typing Python code to include 35 00:01:31.870 --> 00:01:34.000 the new programmes, very frequently 36 00:01:34.000 --> 00:01:36.600 I'll have something like this open on the side 37 00:01:36.600 --> 00:01:39.650 where I will copy and paste from my code 38 00:01:39.650 --> 00:01:42.710 just to see that everything's working as intended. 39 00:01:43.550 --> 00:01:46.330 Instead of writing a code and then running it, 40 00:01:46.330 --> 00:01:48.070 and waiting for it to work, 41 00:01:48.070 --> 00:01:50.020 you can make sure it works by putting it 42 00:01:50.020 --> 00:01:52.330 here first, and checking it first. 43 00:01:53.440 --> 00:01:55.670 This is something that I do very frequently. 44 00:01:55.670 --> 00:01:58.560 Once you want to exit from this interactive interpreter, 45 00:01:58.560 --> 00:01:59.760 instead of closing the window, 46 00:01:59.760 --> 00:02:01.480 which is something you can do, of course, 47 00:02:01.480 --> 00:02:03.980 you can press Ctrl+D, so that's gonna be 48 00:02:03.980 --> 00:02:06.490 Control and D, and I'm gonna press 49 00:02:06.490 --> 00:02:09.360 those two keys simultaneously and then 50 00:02:09.360 --> 00:02:11.830 notice how CTRL+D gets printed out here 51 00:02:11.830 --> 00:02:13.620 and this exits fully. 52 00:02:15.910 --> 00:02:20.300 Now Python runs the default Python version 53 00:02:20.300 --> 00:02:22.340 of macOS X, which is Python 2.7. 54 00:02:23.970 --> 00:02:26.790 If you don't have macOS X, running Python 55 00:02:26.790 --> 00:02:29.510 probably runs the Python version you've installed 56 00:02:29.510 --> 00:02:31.730 at the start of the course, maybe Python 3.6 or 3.7. 57 00:02:33.350 --> 00:02:35.260 If you are on Mac or on Linux, 58 00:02:35.260 --> 00:02:38.170 and you've got multiple version of Python installed, 59 00:02:38.170 --> 00:02:42.340 you can always type Python3.7, for example. 60 00:02:42.340 --> 00:02:44.660 I believe this will work on Windows as well, 61 00:02:44.660 --> 00:02:47.260 but Windows can be a bit picky with the things 62 00:02:47.260 --> 00:02:50.430 that do work and don't work on a terminal. 63 00:02:50.430 --> 00:02:52.610 As you can see, typing Python3.7 brings me 64 00:02:52.610 --> 00:02:57.000 to Python 3.7.0 beta1, this is the early adopter version 65 00:02:57.000 --> 00:02:58.770 of Python that I'm running, 66 00:02:58.770 --> 00:03:02.160 and here you've got exactly the same thing as before, 67 00:03:02.160 --> 00:03:03.510 another interactive interpreter 68 00:03:03.510 --> 00:03:05.310 and now it's running Python 3.7. 69 00:03:07.110 --> 00:03:07.943 What does that mean? 70 00:03:07.943 --> 00:03:09.580 Well, it means you've got access to things 71 00:03:09.580 --> 00:03:13.810 like f strings and things like that, 72 00:03:15.970 --> 00:03:17.770 and not that you'd want to do this, 73 00:03:17.770 --> 00:03:19.940 but just to show you that, in Python 3.7 now, 74 00:03:19.940 --> 00:03:22.150 you have access to all the new Python features, 75 00:03:22.150 --> 00:03:25.280 as you would expect, so if you're typing 76 00:03:25.280 --> 00:03:29.250 a Python 3.7 code in your editor, in your programme, 77 00:03:29.250 --> 00:03:31.420 you'll want to launch a Python 3.7 78 00:03:31.420 --> 00:03:35.090 interactive interpreter in order to test out your code. 79 00:03:35.090 --> 00:03:38.050 If you want to write your programmes in Python 3, 80 00:03:38.050 --> 00:03:40.410 but you launch a Python 2.7 interpreter, 81 00:03:40.410 --> 00:03:41.500 you may find that things 82 00:03:41.500 --> 00:03:44.430 don't quite work as you would expect, 83 00:03:44.430 --> 00:03:46.140 so that's something to keep in mind. 84 00:03:46.140 --> 00:03:47.940 Again, I'm going to exit this interpreter 85 00:03:47.940 --> 00:03:50.900 by pressing Ctrl+D, and now I'm going to show you 86 00:03:50.900 --> 00:03:54.610 a command that is only available in macOS X and Linux, 87 00:03:54.610 --> 00:03:57.680 but it can be used to look at what, 88 00:03:59.420 --> 00:04:02.210 where rather what programme you're running 89 00:04:02.210 --> 00:04:04.890 when you type Python3.7. 90 00:04:04.890 --> 00:04:08.510 See when you type Python3.7 in your terminal, 91 00:04:08.510 --> 00:04:10.270 what's actually happening is that 92 00:04:10.270 --> 00:04:13.870 you're looking for the Python 3.7 programme 93 00:04:13.870 --> 00:04:18.580 across all your folders in your path, okay? 94 00:04:19.920 --> 00:04:22.020 So I'm gonna print out the path, 95 00:04:22.020 --> 00:04:24.410 and you can see that the first folder here 96 00:04:24.410 --> 00:04:28.240 is this Library Frameworks Python.Frameworks Versions 3.7 97 00:04:28.240 --> 00:04:32.580 build, then a colon separates this folder from the next. 98 00:04:32.580 --> 00:04:36.780 When I type Python3.7, I wanna type which before it, 99 00:04:36.780 --> 00:04:40.650 it tells me what programme I'm running when I type Python3.7, 100 00:04:40.650 --> 00:04:42.920 and that is this programme. 101 00:04:42.920 --> 00:04:44.890 This programme is inside Library, 102 00:04:44.890 --> 00:04:46.960 the Library folder, Frameworks folder, 103 00:04:46.960 --> 00:04:49.820 Python.framework versions 3.7 bin, 104 00:04:49.820 --> 00:04:53.980 so you can see matches exactly the first folder in the path, 105 00:04:53.980 --> 00:04:57.390 and then inside bin you've got python3.7. 106 00:04:57.390 --> 00:05:00.650 So this tells us that the python3.7 programme exists 107 00:05:00.650 --> 00:05:02.890 within our path and it also tell us 108 00:05:02.890 --> 00:05:06.020 where exactly in our computer it is. 109 00:05:06.020 --> 00:05:09.840 If you type which of something that isn't 110 00:05:09.840 --> 00:05:14.840 in your path, like asdf, it just won't say anything. 111 00:05:15.632 --> 00:05:16.465 So this is a good way to check 112 00:05:16.465 --> 00:05:18.700 whether you've got things in your path or not. 113 00:05:18.700 --> 00:05:21.330 Similarly, if you type asdf, it'll tell you 114 00:05:21.330 --> 00:05:24.830 come on, not found, so yeah. 115 00:05:24.830 --> 00:05:27.730 If it's not in your path, you'll get a command not found 116 00:05:27.730 --> 00:05:30.580 or similar error in Windows and in Linux. 117 00:05:32.570 --> 00:05:33.480 Now that we know a little bit 118 00:05:33.480 --> 00:05:36.760 about how to actually do this in the terminal, 119 00:05:36.760 --> 00:05:40.270 we can go and look at how we can create 120 00:05:40.270 --> 00:05:43.275 and manage our projects using the terminal 121 00:05:43.275 --> 00:05:45.200 with a couple of tools that we're 122 00:05:45.200 --> 00:05:47.360 going to be introducing in this section. 123 00:05:47.360 --> 00:05:48.910 line:15% I'll see you on the next video.