There are lots of different ways to run your Python code,
but when you get into an actual job, you're going to be using
your command line more than anything else.
And so in this course, we're actually going to look over two different ways.
We're going to go over rather two different ways of running
your Python code.
The first one is the command line, which I really want you
to get familiar with just at the very beginning.
And the second way is using a Jupiter Notebook, which we'll
cover in a different lesson.
But for now, what I would like you to do is open up your
terminal or your command line program.
For me, it's called Terminal.
If you're on Windows, that's probably - 'cmd', 'cmder', or
PowerShell. And if you are on Linux, it's probably like Bash
or some custom terminal that you've downloaded on your own.
And let's go ahead and type 'python -V',
and that's going to show us the current version of Python we're working with.
We can also type 'which python', and it will show us exactly
where the Python program is being called upon.
Now that's actually not super important.
Mines going to say 'pyenv/shims' because I'm using 'pyenv',
yours might say something totally different.
But regardless, it will say something. That's not actually
writing any Python code.
That's actually just figuring out where Python is installed
on our computer and showing us the version. To get into Python,
our Python shell, where we can actually write Python,
just type the word 'python', and hit 'Enter'.
And here we can see that I'm using Python 3.7.2.
I think this is when I set the 'default'.
I'm not entirely sure why that is so far behind, to be totally
honest, but there's a little help in here as well.
So "Type "help",
"copyright", "credits", or "license"
for more information". Let's type 'help'.
Okay. "Type 'help() for interactive help or help(
object) for help about object".
We don't know about objects yet,
so let's just keep this simple and
type 'help()', and it gives us a bunch of information in here.
This is kind of cool.
"Welcome to Python 3.7's help utility!". "To get a list of available
modules, keywords, symbols, or topics, type "modules", "keywords",
"symbols", or "topics". So let's type 'modules'.
Now, we aren't going to learn what all these are right away.
This is just sort of exploring the command line a little bit.
And so that showed me some stuff. That's kind of cool,
but I want to get out of here.
So let's type 'quit'. Did nothing,
or so it seems it did nothing.
What I actually did was get rid of the 'help' tool that we were inside of.
So we are technically inside of a program in our command
line. Now, 'help' is a super useful function when you're just
learning Python.
But to be totally honest, it is not super fun.
I can't run 'clear' because I'm not actually on my command
line. I'm actually inside of Python.
So I'm going to clear up some of the stuff.
And to write your first Python script is incredibly simple.
So type the word 'print', with a parentheses, an opening parentheses;
use a quotation mark, and say
[no audio]
"Hello World", end it with another quotation mark.
We've got an opening one right here, and we have, sorry, we
have an opening one right here, and we have a closing one over here.
Same thing with parentheses,
we have one here, and we have one here.
Go ahead, hit
'Enter'. It says "Hello World!".
And just like that, if you have followed that along on your
computer, you have actually written Python.
It's literally that easy.
So right now we are inside of our Python interactive shell.
We can do all sorts of Python stuff in here, and we're
going to be using this and Jupyter Notebook throughout
the rest of the course as well.
Now to get rid of this, to get outside of this, because currently
we're stuck in like a Python program,
just type 'quit' with opening and closing parentheses, and
you'll get outside of your Python program.
And to get back in, simply just type 'python'.
'quit()'. And if you are one of the unlucky people who has to type
'python3' in order to see the Python 3 program actually
execute on your computer, you simply just type 'python3',
and that will go into your Python 3 shell.
You can actually see for me that changed my version of Python
as well to Python 3.8.
And same thing, 'quit()'.
Now, last thing to note is Python files are usually stored
in some sort of 'python file.py' file.
'.py' is the extension here.
That's the important part.
And to run your Python file is simply just running 'python',
and then the file name.
And so this is getting into command line stuff again, because
this is the program you want to call.
And this is the first argument. You're saying, "Hey, run Python.
But don't just give me the shell,
actually run this file".
Now, this file doesn't exist.
We'll get into that a little bit later. But that is how you
would run a Python file.
One last thing to keep in mind, again we'll talk about this
much more down the road, is Python is case sensitive, and
it's also indentation sensitive.
So we don't use things like curly braces like you see in
JavaScript, or PHP, or in a lot of different languages.
We don't really use curly braces too much in Python.
Instead, we use indentation.
Makes our code nice and easy to read, makes it nice and easy to debug.
And honestly, a lot of people really love the fact that it
uses indentation rather than curly braces. I love it.
I thought it was weird at first, but I actually love it now.
And it is so much better than writing curly braces everywhere.
So what I would like you to do is open up your command line
program, type in 'python', type in 'print(
"Hello World!")'
just like I did, hit 'Enter',
and you'll see "Hello World!",
then 'quit()'.
Once you've done that, you've successfully written some Python,
and it's time to move on to the next lesson.