1.8 Turning Logic into Pseudocode Part 2 - IP

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

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