H, again. In this video I'll show you how to create and how to run a Python program. In the previous lecture
we set up Python and we ran a Python interactive session.
So that was like a running code line by line.
But what you want to do instead, we want to write code that we are able to save it in a file and we're
able to run all the code at once.
So that's what we're going to do in this lecture.
And this is targeted to Windows users.
So if you have a Windows computer please watch this.
If you have a Mac computer or even a Linux computer please skip this video and go to the next video
where I show you the same process but on a Mac computer. So Windows users,
let's create a Python program and we're going to use very basic tools for now.
But then in the next lecture we're going to download and use an advanced editor. On Windows before creating
the program
there is something you need to make sure of. You go to organize and you go to folder search options
you go to View and then look here for this option.
Hide extensions for known file types.
You want to make sure this option is unchecked just as I have it here. Don't check it.
Cancel that and with the option unchecked you go had and right click and create create a text document.
And put a name.
Let's say my program and you want to remove the txt extension.
And want to say .py.
OK.
No problem.
I want to change the name.
Now this is a file where you're going to write your Python code.
So just go ahead and edit, edit it with an editor that you have.
Maybe Notepad.
We're going to use Atom later. For now
this is good.
And this program, what this will do, it will print out some text.
Let's say the 'Hello' text.
So that's what you do, you use the Python print function, and the print function
has this syntax.
So it expects to have some brackets opening and closing brackets.
And inside these brackets you want to pass the thing that you want to print out.
In this case this is called a string. We'll cover strings later.
Or you can say text.
So we want to print out some text and text goes inside quotes always.
So strings go, strings go inside quotes. Make sure you want to save control s, exit the script and then click
outside in here and hold shift and then right click and then you want to go to
Open command window here that you open the command prompt.
Look carefully and you'll see that the command prompt was open.
In this current directory which reflects which is actually the directory of your python file.
So this one in here. This one in here is in here.
So before you run the program you need to have these two directories the same because if you open
the command prompt from here as we did in the previous lecture that will go to another default directory.
So the best way to do it as I did it here.
Click and go to open command window here and then what you do is you type python and then the name of your
program, my program.py. So what you're doing is you're using Python, the python program to execute
this file and you get the output in the command line which is hello, the text Hello.
Similarly I could execute it with my Python 3.6, dot py and you get the same output again.
So 3.6, 3.7 doesn't make any big difference.
The differences are very very slight.
So you don't have to worry about that.
Let me execute it one more time, Python.
If you type now my and if you press the Tab key, that will autocomplete the name of your file.
So it will find the name of your file because it knows that you are in the current directory so use Tab
for auto completion and yeah, again you execute it and you get the output.
Of course you can go ahead and add other lines of code there. Let's say print 7, a number.
Numbers don't go inside quotes, control s to save and close and go to the command line again and press
the upper arrow key to execute, to call a previously executed statement.
So upper arrow key will call Python my program.py. Execute and you get
Hello
and 7. That's the idea.
Hope you enjoyed this and I'll talk to you in the next lecture.