- Welcome to lesson three, control statements.
One of the things that you're going to see
as you get into Python
is that it's a smaller programming language
than some of the other C-based languages
you may be familiar with.
You'll start to see that here
in the control statements lesson
because we have fewer overall control statements
than we do in those other programming languages.
Here we're going to start out by taking a look
at the three different forms of the if statement;
for making a single selection,
for choosing between two different actions,
or for choosing among many different actions.
One of the things you'll notice
as you look at the bullet points here
is that you don't see anything called a switch statement
or a select statement like you may have
in some of those other programming languages.
All of that is done in the context
of the multiple selection
if, elif, else statement.
We do have some interesting pattern-matching capabilities
that we can use with that in Python,
which gives us all the features that we need
from those statements in other programming languages.
We're going to take a look
at the augmented assignment operators
as part of this lesson.
You're probably familiar with things
like += from other programming languages.
Perhaps most importantly, we're going to take a look
at the for statement in Python,
which is for iterating over sequences of elements.
Basically for each item in a sequence, do something.
Unlike all of the other C-based programming languages,
Python does not have a counter-controlled for loop.
What we're going to do as we introduce the for loop
is first, we're going to share you how to iterate
over a sequence, like the characters in a string,
and we'll also introduce as part of this lesson
for the first time, the Python list data structure.
We'll iterate through items in a list,
but we're also going to demonstrate
how you can generate a sequence of numbers,
which is how you would, in turn,
do counter-controlled iteration.
There's a nice built-in function called range
which is capable of generating sequences of integers.
If I wanted, for example, to do a test 10 times,
I could say to do that for each of the elements
in a range of integers from zero through nine,
just as a for example.
We'll also demonstrate sentinel-controlled repetition
in the context of the while repetition structure.
You will notice, by the way,
that you do not have a do while statement
as you do in many other programming languages.
We'll introduce the boolean operators here.
We have the and operator, the or operator,
and the not operator.
Those are all keywords of the language in Python.
They're not symbols like many of the other
C-based programming languages.
We'll introduce the break and continue statements,
which work exactly the same way as they do
in the other C-based languages.
However, unlike things like Java and C#
where you have labeled break and continue statements,
we do not have those
in the Python programming language.
Finally, we'll take a look at a table
of the functional-style programming capabilities
that we'll be presenting in subsequent lessons
and where you'll encounter those
in those subsequent lessons as well.