Hello, everyone, and welcome back to
intro to Python here on Siberry
OnDemand.
As always, I'm your instructor, Joe
Perry. And today we are starting
lesson six Python basics.
Now, for those of you just jumping
in, it may seem strange.
That Lesson six is the python
basics, but I want to thank everyone
who's watched with us from less than
zero all the way up to now, because
you have been through a lot of
PowerPoint and I have great news
about that. There's not going to be
a whole lot more from here on
out. We're going to only use our
PowerPoint slides for the objectives
and to our some reasoned reviews.
The reason for that is because from
now on, we're going to be working
right here in this bad boy, which is
our Ubuntu VM, and we're going do
all of our coding exercises
practically. We're going to talk
about how we work in programing.
We're going to talk about Python and
we're going to do it in the VM with
actual Python code.
We do still, however, I don't want
anyone to freak out if you like to
read your material, if that's how
you learn, that's totally fine.
We're going to have some supplemental
materials for all of you.
We're going to have some cheat
sheets you can find.
We have documentation listed.
I'm also going to show you where you
can find the Python documentation
and their own on the Python manual
tutorial.
All sorts of information you can
find if you're the kind of person
like me who likes to learn by
reading, we're going to have all of
that available to use.
Don't panic.
Here in lesson six.
In our PVM, we're going to have four
main objectives, we're going to
split it up into three videos.
This first video, we're going to
discuss the Python syntax a little
bit and we're going to learn to use
Python on the command line in
the next video. We're actually going
to create and we're going to execute
our first ever Python program.
And then in the final video, we're
going to discuss the python help and
DÃÂ¼rer functions and help enter or
to really, really useful functions
that are built into Python.
They will touch on some advanced,
more advanced material that we
haven't covered yet.
That's totally fine.
We're not going to worry about it
too terribly much.
I'm just going to make you aware
that that's the case and we're going
to use those going to show you how
to make use of them.
So learning to use Python on
the command line and learning about
Python syntax, what we're going
to do is we're going to go over to
our shell, which again, all I have
right here is Terminator, which is a
quality of life upgrade downloaded
that I downloaded onto this VM so
that I can use it for the show.
Nothing too terribly fancy or
special happening over here.
Excuse me.
Water.
So in our terminal, what we're going
to do is we're going to just run the
Python command and this
is going to do is it's going to open
the python interpreter.
However, I want to caution you,
if you just run Python, depending on
your implementation, you may get
dropped into a python to
interpreter, which, of course, we've
talked about Python to needs
to be done dying by now.
Therefore, we're only ever going to
use Python three.
Now, when you use Python, a lot of
times if you run a Python three
program in Python Interpreter,
it will actually work or at least
work for a while because Python
three was designed to be backward
compatible.
However, there are Python three
libraries in Python, three modules
that do not work in the Python
interpreter because they don't exist
for Python two.
Therefore, it's important to make
sure that you're working in the
right interpreter.
So to get to that interpreter, all
we're going to do is first we're
going to clear our screen if I can
learn to type correctly.
There we go, clear a screen and
we're going to type Python.
Three, and the number is right next
to the word python, there's no space
between them that's going to drop us
into the shell we want.
Now, as I mentioned,
a couple of as I've already
mentioned in this video and I've
mentioned a few other times, I
compulsively clear my screen.
I like to have a clean workspace.
And to do that in the python
interpreter is control
very useful command.
Something to know.
So we've got our python hunter,
we've got our python interpreter
open now, and we're ready to start
working to do that.
I want to talk just a little bit
about Python syntax, and this is
something that will continue to
evolve as we discuss it
in our statements and for loop
videos and things like that that are
coming in module two, where we
actually take all of the logic.
We spent Module one learning and we
apply it to Python.
That said, we don't really
have time to go over all of that in
this video. So I'm going to use an
if statement. I'm just going to
trust you not to worry about it too
much until it's time to learn how
your statements work in Python.
That said, it's a useful way to show
you syntax.
So here we're going to say if X
equals equals one, well, first I'm
going to define X.
So the python to yell at me
if X equals equals one
tab.
Prince.
Now, I said tab and I hit the tab
key, and that's actually,
surprisingly enough, a point of
contention for a lot of Python
programmers.
Python in syntax is delineated
is delineated by a white
space. That is to say,
if I had not entered
that tab space here, if
I ran it like this, it wouldn't
work. And we can see that by
attempting to enter that in our
interpreter. And it's going to tell
us expected and indented
block.
So indentation in Python is how you
differentiate what code belongs
to what other what statements
or what functions or what logical
operations or what have you.
When you write an if statement,
whatever is going to be executed as
a result of that conditional is
going to be tabbed in
because it's it's a sum it's
subordinate code to the
state.
Now, the reason I said that tabs are
contentious to a lot of Python
developers is that Python is white
space delineated, but white space
can be achieved with either Tab's
or spaces.
There are people who will avidly
argue for Tab's, there are people
who will avidly argue for spaces,
and I'm going to make both of those
groups upset now until you it
actually doesn't matter that much
so long as and this is the most
important thing, your consistent
within your own code and with
with the paradigm of whatever
organization or project you're
working on.
I personally believe in using
spaces. I like them more and I think
they tend to be more
consistent. Tab's our
time. Width can vary from system to
system and from I.T.
to Ebeid, but everyone's going
to have their style. There are a lot
of people who will actually go to
their tab, who will implement in
their idy that when they hit the tab
key, it will instead insert four
spaces.
When I'm working in the interpreter,
I tend just to use tabs just because
it's a little bit easier in my I.D.,
I often will implement the four
spaces to a rule.
Either way, like I said, the thing
that matters is that it is
consistent because if you do
something like this.
For the first line prints
test.
And then for the second line, you
spaces.
That's actually going to break
the reason for that is because
Python is interpreting the tabs
and the spaces as different kinds of
white space.
So if you're inconsistent, your
program will break either
way for now for this video, use
tabs, you spaces, whatever works for
you. I'm just going to hit my tab
key and keep rolling through.
So the actual incident we set
out to write so long ago, if X
equals equals one print,
it worked
and you can see that nothing
printed. The reason for that, of
course, is because of the
conditional evaluating the false.
And we'll talk all about how to use
those statements in Python down the
road in a different lesson.
For now, we now understand, one,
how to start the Python show.
Two, how to run code in the Python
show. And of course, three, what
python whitespace is supposed to be
used for.
The last we're going to do in this
video is a tradition among
programmers.
We're going to write the phrase,
we're going to give Python the
instruction print Hello,
world.
Now, this is something you can do
along with me or do right after you
watch this video.
Hello, world is a traditional way to
begin as a programmer.
It's just it's the first program
that a lot of people wrote.
And actually in our next lesson,
what we're going to do is we take
this line of code and we're going to
put it into a document and make it
into a Python script.
So with that.
I'm your instructor, Joe Perry.
You've been watching intro to Python
here on Siberry on Demand, and I
look forward to having you in our
next lesson.