As I mentioned in the previous lecture about scripts in Windows, a Python script is actually just a text file in which you can save your Python code when building a larger application. Unlike the Python interpreter, which is basically a live session of Python script allows you to store your application code and run it as many times as you need. Now, to create an edit your Python script, you need a text editor. You can choose any text editor you like. There is no special editor for writing Python code. However, some editors do offer additional features when it comes to programming features such as auto completion, syntax highlighting, and cross platform editing, among others.
In Windows, you can use notepad plus plus for instance, and I'm going to use it to write most of the scripts in this course. However, in Mac OS, a great option is the atom Text Editor. As a side note, at the end of the day, it really doesn't matter too much. Whether you're using pythons default IDL, or pi charm or Jupiter notebook, or regarding text editors notepad plus plus or atom, I see many students of mine focusing on one ID or the other on one text editor or the other, instead of keeping their eyes on the ball. And that is the code. I've had some students complaining right from the start of the course, about my choice of text editor or ID before they even had the chance to write their first line of Python code.
Trust me when I say this, please learn to code master the concepts, the syntax, the libraries that we're going to use, and discuss throughout this course. Do your own additional research and testing. Solve the exercises and quizzes in the course. Save all the notebooks, ask questions, be curious about programming, and then you'll soon realize that putting too much thought into Text Editor A versus text editor B is really a waste of time. I haven't heard of any great Python programmer who got rejected at an interview because of his choice of using one ID over another. So keep your eyes on the ball.
Okay, now back to our scripts. To get the atom editor. Just open up your browser and go to atom.io. Click on Download right here. And then as soon as the download is complete, just install atom as you would do with any other software package on Mac OS, you can then open up atom by simply going to your terminal and typing in atom. Okay, there it is, it's now time to write your first Python script.
Let's do it together. I'm going to use perhaps the most famous Python function, the print function that does nothing more than to just print the string in between it's parenthesis to the screen. So I'm going to type in print Opening close parentheses and in between double quotes, I'm going to insert my string, let's say hello, Python. That's it. Now let's save the file using command x. I'll call this script, my underscore script. And very important here, do not ever forget this, I will also add the dot p y extension, you need to add this extension to every Python script that you create following the file name, of course, and I'm going to save the file in my documents directory.
So I'm going to hit save. Assuming you did the same, I have to honestly congratulate you, you just built your first Python script. Now in order to run this script, you can go over to the terminal and type in Python three space and now the path to the file and of course the file name including the extension. So that would be documents slash my underscore script.py. As soon as you hit enter, the script gets executed, and the Hello Python string gets printed out to the screen as expected. Great.
Now you know how to properly create, save and run a Python script. I'll see you in the next lecture.