>> Hello everyone and welcome back to
Intro to Python here on Cybrary on-demand.
I, as always, I'm your instructor
Joe Perry and today we're going to be in Lesson 6.
This is going to be our second video of Lesson 6,
where we're going to create and execute
our very first Python script.
If you were with us in the last video,
you'll know that we performed a HelloWorld.
We printed hello world to the screen by
executing [NOISE] the following line of code.
Let me retype it real fast.
You think I could have just left it up,
but oh, well, anyway.
Here's the line of code we ran,
printed HelloWorld now what
we're going to do is we're going to take that line of
code and we're going to turn it into a Python script.
First and probably foremost,
we're going to go ahead and quit our Python shell.
We're going to clear our screen.
Now, I'm going to be working in
Vim for the rest of these videos.
I love Vim as a text editor.
I don't generally go in for really big IDEs.
It's the same way that everyone has their own style,
but a lot of authors actually prefer to
write with typewriters or with
old-school word processing tools
that don't really have a lot of features on them.
It's all about your style and what you know.
I learned to program on a very simple,
basically what you see here,
text on a black screen
so that's what I'm comfortable with.
That's what I like and that's what I'm best at.
We're going to work in
Vim and for those of you who've never
used Vim or those of you who just downloaded Vim,
a useful piece of information.
It's not really that relevant
to this course other than that,
it will make the rest of your programming a lot easier.
If you use Vim to edit
the Vim RC file or the Vim configuration file,
which is going to be found, generally speaking,
in your Etsy Vim, Vim RC.
Now, depending on your installation,
depending on the system you're on,
it might be.vimrc,
in my case, it's just Vim RC.
You can open that up and edit it.
Let me [NOISE] type my super secure password in here.
You can see I've already got it down to
the part of the page that is relevant.
On yours, if you haven't edited this,
all of the lines that just
disappear for some reason, here we go.
[NOISE] There we go.
All of these lines right here,
those are configurations for Vim
that are probably commented
out if you've not edited this.
Just go through and delete the
quote that's at the beginning,
and that'll enable these.
Additionally, I also set auto-indent,
which you can see right here,
and all that does is it
makes as we talked about in our last video,
where Python uses tabs spaces, what have you.
What it does is it takes
whatever the indentation of the previous line
was and it takes it back and
it puts that on the new line when you hit, "Enter".
Saves you just a little bit of typing and it's one of
those qualities of life upgrades
that I really appreciate.
Additionally, I'm going to go ahead and
should not be in visual anymore.
I'm going to go ahead and find a dark,
there it is and set background equals dark.
That just makes it a little bit easier
to read on a dark background.
Now I'm wrong command pwd.
I'm currently in Lesson 6 and we're going to
create our very first Python script.
What we're going to do is we're going to
run the command to Vim and
I'm going to use the name hw.py.
So.py is the Python file extension that tells your shell,
that tells your operating system this is a Python file.
It also tells your editor that this
is a Python file if you have
syntax highlighting for Python.
Then in our file,
all we're going to do at
first is we're going to write this line.
Wrong thing there. [NOISE] Now
this line is actually not mandatory in Python,
it is very useful however,
because it allows you to make
your Python script executable.
I'll show you the two ways to run
a Python script here in just a minute.
But by doing this, we call that
a shebang that's what these two symbols right here are.
Depending on your generation,
that is either a pound sign,
a hash mark, a comment mark,
a hashtag, point is,
that mark right there that
looks like a tic-tac-toe game,
that and the exclamation mark together,
that's called a shebang and that's just an indicator to
the Linux operating system that this is
a Python script and that it can be run
using the Python three interpreter found in user bin.
In the last video, we were at
HelloWorld and at the beginning of this video,
I showed you HelloWorld again from the command line.
To do that in a Python script,
all you have to do is write exactly that command again.
[NOISE] But now instead of
running automatically because you're in an interpreter,
or because you're not in an interpreter, rather.
Instead of running automatically,
it's just text, it's just written to the document.
Once we write it, we can quit.
[NOISE] Now to run this,
there are a couple of different possibilities,
if we didn't have the shebang line,
we can only do it by running
the command Python 3, and then the file name.
In which case bam, we've printed
our first-ever HelloWorld.
Or [NOISE] we can do,
chmod is a command that will set
that file to be executable with the 777,
setting the specific permissions that
are basically just all permissions.
Helloworld.py, hw.py and you can see
here that the color changed on it is now executable.
Then you can run it on your Linux command or on
your Linux terminal just by doing./hw.py.
Dot slash just says
look in the current directory for this.
There you go, once again,
we've run hello world.
Either of those options works.
Most Python programmers will include
the line at the top of the file to make it executable.
It's really all about your personal style.
It's not mandatory, but it's very commonly used.
That's all there is to it.
In this video, we learned how to write HelloWorld.
We learned how to take the Python code
that we were doing in the interpreter,
put it in the document and run that document.
From here on out, we're going to be
able to really do some actual Python program.
We're going to spend all of our time and the VM,
very excited for it.
Our next video is going to be the last actual lesson or
the last informative video of
Module 1 after that it's just our review.
Tune back in and we're going to talk about DER,
Help and the Python documentation.
As always, I'm your instructor
Joe Perry and thank you for
watching intro to Python on Cybrary on demand.