1.9 Turning Logic into Pseudocode Part 3 - 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.
00:00
This is Lesson 6 of intro to Python on
00:00
cybrary on-demand and I am your instructor Joe Perry.
00:00
In this video, we're going to cover
00:00
the last objective of Lesson 6,
00:00
and we're going to learn to use the Python help
00:00
and their functions,
00:00
and we're also going to take just a second to
00:00
have a look at the Python documentation.
00:00
To do this, we're going to
00:00
work in our interpreter once again.
00:00
Again, we're going to type Python
00:00
3 at the command line,
00:00
and we're going to open a Python 3 interpreter.
00:00
The first function we're going to look at is help.
00:00
Now, help as I said is a function which means that it
00:00
is executed by putting the parentheses after it.
00:00
We're not talking about functions very deeply yet,
00:00
we'll do that in a later video.
00:00
But once you run that command,
00:00
it's going to open up
00:00
this new subprogram that is
00:00
the help program inside of the interpreter.
00:00
You can see the instructions there.
00:00
Give it the name of a module or a keyword,
00:00
or basically any Python topic
00:00
and if it has information about it,
00:00
it will give you that information.
00:00
Now, it can be a little bit tricky to use at time,
00:00
just because for example, things like strings,
00:00
which are very important components of Python,
00:00
you don't actually find by writing the word strings,
00:00
but it will try and give you information.
00:00
For example, use help serve for help on the str class.
00:00
It will try and give you information about how to search
00:00
for whatever you're trying to get help on.
00:00
Anyway, we're going to look at an example of this,
00:00
which is just going to be the print function.
00:00
You can see here, if you're familiar with the man pages,
00:00
this is going to look pretty familiar to you.
00:00
You've got your function at the top,
00:00
and then after that you've got
00:00
a description of how it's used,
00:00
what arguments you would give it.
00:00
Then you have an actual text description
00:00
prints the values to
00:00
a stream or to assist out standard out by default,
00:00
sys.stdout is standard out,
00:00
that just means print it to your screen.
00:00
Which of course we've demonstrated
00:00
even if we don't really know what functions are yet,
00:00
we've demonstrated what print actually does.
00:00
This is just giving us an explanation
00:00
in a verbose way with more information about arguments.
00:00
That's what help looks like,
00:00
you can use help again for pretty much
00:00
any module keyword or symbol if it has documentation,
00:00
Python we'll be able to provide it.
00:00
You leave that just by typing quit,
00:00
now that's different from quitting your shell,
00:00
which has done with quit with [NOISE] parentheses.
00:00
In the help documentation,
00:00
you just write the word quit.
00:00
We've learned to use help.
00:00
Now we're going to learn to use dir
00:00
and dir is a tricky one to
00:00
explain without a lot of knowledge of Python,
00:00
because it deals with a topic called namespaces,
00:00
and that's something we're not going to spend
00:00
very much time on it all right now,
00:00
other than to understand that a
00:00
namespace basically just means
00:00
the current environment in which you're executing code.
00:00
It give you a better way of understanding
00:00
that are more clear way,
00:00
we're going to run dir right now without
00:00
any other arguments or rather any information.
00:00
This is a fresh shell,
00:00
we haven't really done anything in it yet
00:00
that would modify any information.
00:00
You can see that we have these list
00:00
of items with these underscores around them.
00:00
Underscore is basically an indication in
00:00
Python that those are internal functions,
00:00
they're not really for use
00:00
by the programmer or by other programs or other modules,
00:00
those are built-in parts of your current namespace.
00:00
Now, if you want to see how you can modify a namespace,
00:00
a simple example would be creating a
00:00
variable which we will call x,
00:00
and another variable we will call y.
00:00
Now, nothing has happened here because we
00:00
were assigning to these variables.
00:00
Even though we're in a REPL which
00:00
generally reads, executes and prints,
00:00
it's not going to print because it's sending
00:00
that information to the variable instead.
00:00
But we've got x equals one, y equals A.
00:00
What we're going to do now, is we're going
00:00
to rerun that dir command.
00:00
You can see at the end of the list,
00:00
these two new items have been included, x and y.
00:00
Those are the variables we just created and that's what
00:00
the namespace is and that's why I wanted to address it.
00:00
What this is,
00:00
is it's going to show you everything that is
00:00
currently defined that you can have access to.
00:00
Additionally, if you run it with command, for example,
00:00
running it against one of those variables
00:00
, not what I meant to do,
00:00
[NOISE] you'll see a bunch more options.
00:00
These are all of the things that are
00:00
defined within the number variable.
00:00
These are all of the functions,
00:00
the methods that numbers have access to.
00:00
To give an example of that, we can see x.numerator,
00:00
which is actually not a method, it's an attribute.
00:00
The numerator of course, of one is one,
00:00
and we're going to go ahead and clear that screen.
00:00
That's help and that's a dir.
00:00
Those functions like I said or utility functions,
00:00
not only will they become easier to
00:00
understand as we go forward and videos,
00:00
you're going to find more uses for them.
00:00
You can do a bunch of stuff with both of those functions.
00:00
I'll give you a ton of information.
00:00
Oftentimes when you're trying to run down an error,
00:00
those are the places to start because you'll be
00:00
able to figure out what's happening with them.
00:00
The last thing I want to show you here,
00:00
and I think I might still have it up in my Browser,
00:00
the Python 3 documentation.
00:00
This is the https://docs.python.org or those backslashes,
00:00
I can never remember which direction
00:00
you call it a slash either way,
00:00
docs.python.org, and then it's
00:00
the Python 3.7.2 documentation specifically.
00:00
You can see here this menu, you've got Python 3.8,
00:00
which is still in debt for people
00:00
who are using it ahead of time.
00:00
3.6, 3.5, and 2.7.
00:00
Now we're currently working in 3.6, but like I said,
00:00
none of the coding we're going to be doing in this part
00:00
of the class or in this class really in general,
00:00
is going to run into any differences
00:00
between 3.6 and 3.7,
00:00
we're not going to worry about that.
00:00
Between now and the intermediate in the advanced classes,
00:00
we're going to move on to actually
00:00
using the proper Python.
00:00
Anyway, that's the Python help documentation,
00:00
it shouldn't close that window,
00:00
I'm not done with it at all.
00:00
That's the Python help documentation
00:00
you can see that they have tutorials,
00:00
library references, language references.
00:00
In fact, this tutorial I do want to draw
00:00
attention to is absolutely spectacular.
00:00
It's all part of the Python installed.
00:00
It's all part of Python.
00:00
It's free to use and free to read.
00:00
I absolutely love it, and in fact,
00:00
a lot of our material in this course is
00:00
going to be based on information in that tutorial.
00:00
In the intermediate and in the advance,
00:00
we step away from what the tutorial covers.
00:00
But in this intro course, you can absolutely use that,
00:00
that's one of the best supplemental
00:00
resources you can have access to.
00:00
That's the end of this video,
00:00
and therefore that's the end of Lesson 6.
00:00
In Lesson 6 again,
00:00
we discussed the Python syntax,
00:00
how to use Python command line,
00:00
how to create and execute Python scripts,
00:00
and how to use the help and the dir functions.
00:00
All of those things, again,
00:00
are going to not only make more sense or become
00:00
more relevant with each passing video,
00:00
I just wanted you to be introduced to them now,
00:00
so that we're ready to roll.
00:00
Please join us in Lesson 7,
00:00
where we're going to be discussing the Python data types.
00:00
As always, I am your instructor Joe Perry,
00:00
and thank you for watching this video intro to
00:00
Python here on Cybrary on-demand.
Up Next