- [Instructor] In our previous video,
we got Python installed.
Specifically, we installed version 3.8.1 of Python
and we saw that if I just typed in Python
in my command prompt,
it's going to run the version
that I already had installed on my Mac, 2.7.
So I if want to run a specific version of Python,
I need to specify it.
Let's get out of this version by saying exit.
By the way, exit, that's a function.
And a function has to begin and end
with an open and close parentheses
so I'll do an open parentheses, close parentheses,
and press Enter.
Now if I want to run some version of Python 3.8,
I'll say python3.8.
And we can see that I'm now running version 3.8.1.
And we're now sitting at the Python interactive interpreter
and I love this environment
because I remember back in college
when I was learning to program
in the C programming language,
I would have to write a program,
I would then compile it,
and then I could run the executable that I had compiled.
But Python is super convenient.
We get to give a command and it executes right away.
For example, I could do math function.
I could say 2 times 2,
where the multiplication symbol is the asterisk.
2 times 2, press Enter, and it tells me 4.
Or I could print a string.
Normally when you're learning a programming language,
the first program you write says "Hello World."
Let's do that.
I'll say print, and this is a function,
so I do an open parentheses,
and "Hello World" is a string.
It's not some sort of a number.
It's not an integer.
It's a string of characters.
So I'll say open quote, "Hello World!" exclamation point,
close quote, close parentheses and we'll press Enter.
And it says "Hello World!"
However, there is another interactive interpreter
that I actually prefer to this.
Instead of going to a command prompt and saying Python
followed by the version,
we can go into what's called
the IDLE programming environment.
IDLE, I-D-L-E.
That stands for Integrated Development Environment.
And in addition to giving us an interactive interpreter,
IDLE gives us some color coding.
It's going to help us
keep all of our open and close parentheses
and open and close quotes correct
when we're doing a really complex function
because we might forget to close a quote, for example.
We'll get some color coding to prompt us about that.
Now to run version 3.8.1 of IDLE,
I first need to get out of this.
I'll say exit, open and close parentheses,
and then we can say I-D-L-E 3.8 and press Enter.
All right, we're sitting at the IDLE prompt now.
This is an interactive interpreter
and I've already gone in and said File, New File,
because what we're going to be doing in this video
is after we demonstrate that we can give commands
at the interactive interpreter,
we might want to create a file full of commands
and then we can save and execute that file.
That's going to be helpful
when we're doing more complex programs.
Maybe we're prompting the user for input,
or we're reading information from some other external file.
But first, let's just check out
this IDLE interactive interpreter.
Let's do that Hello World that we did before.
I'll say print, and it's a function
so I need to do an open parentheses
and notice it gives me some syntax help as I do that,
and I'll do an open quote,
and notice it's in green and when I close it,
it's going to stop being green.
Now that's going to tell me
that I've closed my string of characters.
And I'll say "Hello World!" exclamation point.
And now I'm going to do my close quote.
And when I type the next character, the close parentheses,
it highlights all that to show me
that the function is complete and when I press Enter,
it comes back and says "Hello World!"
Now let's say that we wanted to write a program.
We could go under File and say New File,
I've already done that, and we could write a program here.
For example, I could say print, open parentheses, quote,
"Hello World!" exclamation point,
close quote, close parentheses.
And I could save this.
Let's do a File, Save As, and I'll call this
helloWorld.
Now if I want to run this, I could say Run,
Run Module, and the output is going to show up
under the interactive interpreter pane.
So I'll say Run Module
and it comes back and says "Hello World!"
And again, creating a separate file is a good option
when we have a more complex task we're trying to do
where we're maybe prompting a user for input
or reading information from a file,
or we want to output information to a file,
we could write a fairly complex program.
If for example, when we're doing a program
that's going to do some network configuration,
we probably want to write that inside of a file.
By the way, one word of caution here.
Sometimes we have the temptation
to just break out a text editor, any old text editor,
and write our program in that.
For example, if I wanted to use the text editor
that came with Mac OS, which is just called TextEdit
and I opened up a new window
and I typed in print, open parentheses, open quote,
and I said "Hello World!", exclamation point,
close quote, close parentheses.
That looks maybe okay but it's really not.
If I copy this and I paste it
underneath my previous command, look what happens.
Suddenly, "Hello World!" is not in green.
What's going on?
Well notice when I typed it in using the IDLE program,
it gave me straight quotes
but when I used my text editor,
it actually gave me an open quote and a close quote.
They look a little bit different than the straight quotes.
We need to be using straight quotes.
This program would fail to run,
so we need to make sure we're using a text editor
that's going to to give us straight quotes
and some text editors are designed with programming in mind
and they're going to give us color coding
and all those helpful features that we get with IDLE,
but just be careful and don't run just any text editor
that might give you the wrong type of quotes.
Now in this video,
we've seen how to get into an interactive interpreter
at the CLI or in the IDLE environment
which gave us the benefit of some color coding.
We saw how we could create a Python file
that we could then execute later.
And finally, we cautioned you about using a text editor
that might not use straight quotes.