Enroll in The Complete Python 3 Course: Beginner to Advanced!
Click here to subscribe for more videos like this!
So, the interpreter, and this is going to be a short video I think, but we’re basically going to talk about the difference between an interpreted programming language and compiled programming language, and this might be a little adept for the novice programmer but just stick with us again if you have any questions or not sure if you completely understand it, there’s a discussion section to the right of this video, yes should be right to the right of this video, so use that and I will try and clear up any confusion. So, first, with a compiled programming language you write your code and you save it into this file, and you can’t run that file yet. Let’s say you’re writing C++ code, so you write a function, you write a script that will do something. If you try and open that file with the .cpp extension, which is for C++ files, it is just going to open that in a text editor or code editor because that’s not an executable file. What you need to do with a compiled programming language is once you save your file you need to compile it into a language that the computer can read, so binary ones and zeros, and by compiling this file into an executable file, then you can double click it and it will run. So, if you’re on Windows building executable files for windows they will have a .exe extension. If you’re on Linux I don’t believe they have an extension. So, the difference here is with Python when you write a script you can instantaneously run that script without having to compile it into binary and because we can do that what’s actually happening is when you run the Python command you’re not running the file standalone. So, when you compile a programming file into a binary file you can just type the name of that file in the terminal or command prompt and hit enter and it will run that program as a standalone program because the computer already knows how to run it, but when you run Python scripts you’re going to run it with the Python command and then the name of the file, and what basically happens is you’re running the program Python which is interpreting your code and running that. So, what happens is it does compile into binary but it does what’s called just-in-time compilation, and what that does is every time you run its going to parse all the code and it’s going to convert it into a temporary file and then run that temporary file. So, let me break out of this, there. So, how you would run a script and we’re going to talk about that later but basically how to enter the interpreter on its own you just type python3 to use the three version of Python you can see the version we are using Python 3.5.1. So, basically in the interpreter you can run real time code, so if I were to type “print hello world” it’s going to instantaneously run that line of code. If I run “4 + 6” it’s going to return 10 because that’s the sum of four and six, and so the interpreter is great to use if you want to test something really quick, if you want to debug a few lines of code, or if you just want to see if something would actually work. So, we’re going to be starting out using the interpreter but as things get a little more complex we’re going to get into writing scripts and executing those scripts. So, now we need to learn how to run a Python script.