/ factorpad.com / tech / full-stack / python-keywords.html
An ad-free and cookie-free website.
Beginner
Videos can also be accessed from our Full Stack Playlist 3 on YouTube.
Introducing Python keywords | Python for Beginners (4:52)
Welcome. Today's question: What are the top 5 keywords for beginners?
I'm Paul, and I create five minute videos to help people help themselves, because it's so easy to forget words in a new language.
So here we will find that list of keywords from the last tutorial, and start exploring these reserved words in Python, like operators.
Starting with True
and
False
, the focal point of conditional
logic in programming.
Then we will play with
and
,
or
,
not
operators before moving on to
text functions.
(Commands in Linux)
pydoc3
less
(Keywords and functions in Python)
True
False
and
or
not
help()
exit()
Let's head to the Linux Terminal, and currently I'm using Python version 3.4.2.
Online documentation can be found at https://www.python.org/doc/versions/ by version number.
Now let's find those keywords locally.
Here is a file with the 33 Python keywords, and I'll use this file in the future so we can keep track of our progress, including five in this tutorial (number 29).
Below that are instructions for how to access this list in Python yourself, which is often less distracting than a Google search, right?
The last tutorial demonstrated how to access documentation on the local machine using interactive help and object help.
Run python3
, then type
help
to identify the two types.
First, interactive help, using help()
like this and it gives you a different command prompt.
Type keywords
and there they are in
alphabetical order, the first three starting with capital letters.
To return to a Python prompt, type
quit
.
Now, object mode, accessed from here, using
help
and an object like a function
name (type
).
(Type q
to return to the Python
prompt).
Or a topic like 'keywords'
in single
quotes.
Very good.
So what should we know about reserved words called keywords?
First, they must be used with exact spelling, so
True
is
True
.
But this true
creates an error.
Second, you don't want to name variables using keywords, so yes,
while 'the sky is blue'
is
true
, lowercase true.
We can't name it True
, capital True
or Python yells at you.
And third, which illustrates why compatibility can be an issue, keywords do change across versions in Python. Keep that in mind.
So True
and
False
are Boolean values, or outcomes
from comparison or relational operators in Python.
Logical programs follow this
True
and
False
path, and they translate to
number, right?
So True
is
True
and
False
is
False
.
Does True == 1
?
Ah, so then False == 0
, right?
And here's an odd one, what is
True + True
.
Not four, it's two.
And we went through an exercise with operators like this back in
tutorial 24. Remember 1 < 2
?
Then 1
is not equal to
2
.
So if we did 1
is less than
False
.
We get False
.
And 1
is greater than
False
.
We get True
.
So the takeaway, True
is 1,
False
is 0.
Let's move on to and
, which means
that all operands must be True
in
order for the whole statement to be
True
.
So True and True
is
True
.
True and False
is
False
.
False and True
is
False
.
What is False and False
?
It is False
.
Next is the or
keyword. Here the
whole statement is True
if any of the
operands are True
.
So True or True
is
True
,
True or False
is
True
,
False or True
is
True
.
What is False or False
?
It's False
. We can't overthink it.
Finally not
goes like this.
If it's not True
it's
False
. That's basic. And if it's
not False
it's
True
.
And if you wanted to program like a lawyer, and confuse everyone, you
might do a not not not False
,
;)
.
So to help, here are a few tables. Stick with it until you can generate these from memory.
Below is a homework problem. Pause here and write it down.
Here is where we are heading on our journey, using this software stack.
You are invited to join, simply Subscribe to get new videos and up next we cover functions used for text.
Have a nice day.
For reminders of new content follow @factorpad on Twitter, our email list or subscribe on YouTube.
/ factorpad.com / tech / full-stack / python-keywords.html
A newly-updated free resource. Connect and refer a friend today.