Transcripts
1. Intro: Welcome to the Python
programming course. My name is Mark Bukowski and I thank you for choosing
this training. I've been working
for many years as a DevOps and Cloud
administrator using Python as a tool to automate
many mundane tasks. Python is very useful and extremely popular
programming language, and it's used in AI, in automation, networking,
and many other fields. This training is designed
to take you from having zero or very little Python
knowledge to complete understanding as quickly as possible and we
will learn Python by writing code and building stuff rather than just
talking about it. In the second lesson, you will not only have already
Python installed, but you will also have your
first program written. If you are starting your
Python journey from scratch, I suggest watching
these videos in order as they appear on
the platform, I mean, because jumping straight to a random video might be
a little bit difficult because some of them may rely on the concepts discussed
in previous materials. I hope you find this training informative and I thank you
for choosing this training.
2. Python installation / first program: In this video, we
will install Python. We will see what
Interactive Shell is, and we will also write our
first program in Python. Let's start from the
installation process then. We'll see how to install Python on Windows,
Linux and Mac, and I will start from MAC because that's
the easiest part, and it's the easiest because the Python is already
installed on your Mac. This is my Max terminal, and you can check
what version of Python you have installed
by typing either Python. Version, it's dash dash version or Python three
dash dash version. You can see I have Version
3114 of Python installed here. I didn't do that. It simply came with that Python installed. There's also shorter
version of that command. You can run just Python one dash and V, and
then Python three. Regardless of operating system, you should always check
both those commands. The reason that one might
work and the other will not is because Python
has two major versions. It's Python version two
and Python version three. That first letter is so
called major release, as you can see, it's
Python version three, and that's the Python
we're interested in. Now, if you have older
Mac I mean very old MAC, you might have only Version
two of Python installed. Which most probably will be shown when you run this command, Python V. If that's
actually the case for you, then you need to install
Python in version three because that
is the version we are going to work with here. It's very easy. You can
simply go to Google and just type Python Mac Install
or something similar. And if you go there
to downloads, you can see download the
latest version for Macs. So you just click this button and follow the instructions. But being on the Mc, it's probable that you're using the Home Brew
package installer. Then you can run just Brew
update and Brew upgrade. And once that is done, you can follow it with
Brew Install Python three. And this command will install Python inversion
three on your Macs. I have it already installed, so I will not run it, but this is the command
you are interested in. That's Macs D. I will show you now how to install
it on Centos seven and they specifically chose
that old operating system so you can see exactly
what I'm talking about that Python
two, Python three. If I go to that Centos, let's go to Santos. This is the Sent server. If I run Python version, I've got Python in version
two installed here. It was pre installed as well. I didn't have to install
it, but it's version two. If I run Python three version, it says command not found, but I need Python three,
so I have to install it. It's super easy though. It's just pudo hum update first, just to make sure that our
packages are up to date. The information about
packages is up to date. And once that's completed,
as you can see, it's complete, you
can just run sudo, you install IP three. Yes, firm. That was quick. Now let
me clear that again. If I run Python version, I've got Version two.
It's still there. But if I run Python
three version, I have also Python
in Version three. That is very important to
understand because we want to run the command that refers
to Python version three. I hope that makes sense now. On this particular sentence, I would have to run
always Python three. But it's not always the case. If we jump to Ubuntu now, that's the other server,
that's the Ubunto. So this one, the first one. If I run Python version, doesn't show anything because it doesn't come with Python
version two installed. But if I run Python
three version, it has Python three
already installed. I didn't install it. It
just came with this Python. But you might be on
Santos or boom to server, and you run Python,
this first command, and it will come back with
Python in version three, because it's very easy to
create a so called sim link for this command to
refer to that command. I know it's a bit confusing, but both those commands would
give you the same output. People usually don't install Python in version two anymore. People usually need only
Python version three. What is important for us, we have to know which
command we can run, so we work with Python
in version three. As I said, this Ubuntu came with Python
three pre installed. But if I didn't
have it installed, the process would be very easy. The installation process
would be very easy anyways, and it's basically the
same as I sent seven, only Ubuntu uses
at packet manager, which means we have to
run sudo UT update first. We used to run sudo Hum
update, if you remember, on Santos and Sudo
UT update here. Okay, that's completed. Once that's done, we run sudo
upped install Python three. Instead of Hum, we just use UT. That's the
only difference. Enter, you can see it says Python three is already
the newest version, at least from the official
installer package installer, so it didn't do anything really. But that's basically it. So we've got MacOS and Linux. Let's check the Windows now. On Windows, I can open
terminal by typing CMD. This will open my terminal, and they run the same command. Python version, says
Python not found. Always remember to run the other command
Python three version. But it also says
Python not found because Windows doesn't come
with Python pre installed. So we'll just find one.
We'll go to Google, Python install Windows,
something like that. We just go to first Link. Downloads. And it says, download the latest
version for Windows. That's what we want to
do. Click download. Once it's downloaded, I
just click the Ex file. Normal installation with just one little
difference right now. It says, add Python ex to Path, and that's what we
really want to do. Because if we don't
do that, it's possible to do it later on, but it requires some knowledge that we can just click
the bottom and that's it. We don't have to worry
about anything later on. So once you have that ticked
at Python exit to Path, we can just follow standard installation
process for Windows. I click Install Now,
then just close. The other little thing, if you go back now
to your terminal, and if you repeat
those commands like Python version and
Python three version, you can see it still
says Python not found. You simply have to close
it and just reopen it, C and D. And now if
you run it again, Python version, you've got
Python three installed. And if you run Python
three version, you can see Python not found. And now you see my point. You always have to
run both commands because Windows behaves
completely different way, even though it's Python
in version three. You have to run standard Python command rather
than Python three. But as long as you
know which command to run on your operating system, that's fine. Doesn't
really matter. All right. So that's Python installed on all
operating systems. And now we have Python
installed, but so what? How do we work with it? So the first option is that interactive shell
I was talking about. And maybe let me close that. I will terminate those
servers as well. We don't need them
anymore. I can just use standard Ubuntu
that I have locally here. Here I have to run
what Python three. Version. It's the
same version that I had in AWS on
the other server. It's different ubuntu
but the same version. So if I now just run Python
three without that version, just Python three,
this will take us to what's called
interactive shell. And the interactive
shell is a place where you can write instructions
for Python to process. And the most popular
task that you usually do when learning any
programming language, not only Python, but any, is to display words hello world. And in Python, we can do it
by using print function. So it's print, and then function has to have
those brackets. So what we can do
inside those brackets, inside quotation marks,
we can write Hello world. And if I click Enter, Python, displays back the words that
I put in those brackets. The print function is simply instruction for Python
to process anything that we include inside
those brackets and display the result back on
our screen as it did here. And in this example, Python didn't have much to do really, but that print function can be used for
many other things, like we can use it as a
calculator, for example. If I type print, and now let's say three
multiplied by four, don't know, we use the
asterisk to multiply numbers. So if I clcanter
now I get back 12. Python first processed
whatever was in those brackets and only then displayed the result
back on the screen. The same if I want
to divide something, let me just use up arrow, I can do 2/7. So this forward slash is
used for division in Python. If I clcanter, I have
the result back. You might have
noticed that I wrote those numbers without
quotation marks, though. While previously
that hello world, I had to include that
inside quotation marks at the beginning and at the end. This is how Python processes
different data types, and we will learn about those data types more
in dedicated video. But for now, I wanted to show
you that you can do stuff that at first sight might not make much sense
because if I run, for example, something
like I don't know, print, and then I don't know,
ten times hello world. Might think, that's silly. But if I click
Enter, Python simply displayed ten times
string hello world. Yeah, because those words
here inside quotation marks, they're called
strings in Python. Somebody might say, that's cool, but we were supposed to write a program here, if I
remember correctly. Yes, that's correct. And that's what we
are going to do now. But that interactive shell, it's very useful if you
want to, for example, test quickly some stuff, if you want to check
some commands, but it allows you also
to run multiple lines. It doesn't have to be one line, but it's simply a tool
available within Python. You will find very,
very useful later on. But for the time being,
let's get out of this interactive
shell to get out, we can actually use another function and its
function called exit. Because it's a function, we always have to follow
it with brackets, we don't have to put
anything in those brackets. We can just click Enter. The other way to exit
the interactive shell is Control D on Mac or
Linux or on Windows, you can type Control Z
and then click Enter. So how do I write a
program in Python? To write a program in Python, I just need to create a
file with dot PY extension. That's it. Let me clear that. And I can use any text
editor that I want. It doesn't matter
which one I use. In Windows, you can even
use note but on my Ubuntu, I can use VM, for example,
or, you know what? Let's just go first.
What is text editor? Okay. Let's just use this text editor, and
I will write what? Print. We had Hello world. But I can then write like what? Print to divide it by seven. I can also print maybe 20 times my first
program. My spaces. And now I can save it. Mark. Save. I showed up here, so I can close it,
but how do I run it? I run it using Command Python three and
then path to this file. 1 second, let me just
control see where home. I will go to desktop. And this is my file. This is this file, Marc dot py. Now I'm in the same folder,
I'm on the desktop, so I can just run Python
three, Marc dot py. If I click enter, I
can actually 1 second. If I run cut, Mark Pi, it will show me the commands. I will show me my
program basically, so we can see it followed
those instructions. It first printed hello world, then it divided two by seven, which is this, and then it printed 20 times
my first program. Without spaces, we could
add space here at the end. You know, the formatting isn't
perfect, but never mind. And I know it might
be very simple, but that's basically it. That's your first
Python program.
3. Data types: In this material,
we will talk about data types used in Python. The most popular data
types are string, integer and floating
point number. So let's start with
the string, maybe. Python string is a collection of various characters
that you can find on your keyboard that we then enclose in either single
or double quodes. And those characters
can include letters, numbers, and special
characters like question mark. Spacebar is also
considered a character and can be used as a
part of Python string. As long as they are all inside
single or double quodes, Python will consider that
as a data type string. And now you can see this
plate some examples of string data type and
note that they are all in either single
or double quotes. Let's talk about
the integer now. Integer is simply
a whole number. It can be a positive
number like ten. It can be a negative number like -200 and zero is also
considered an integer. As long as it's whole number and it's not in a single
or double quote, it will be considered by
Python as integer data type. Then we have floating
point number, and floating point
numbers are simply fractional numbers like
2.5 or I don't know, 8.44, something like that. And they are also not
inside any quotes. We just write them as they are. Okay, but let's play with those data types directly
in Python because, you know, seeing just the theory does not explain it well enough. We have to see it in action. So this is my UBT server, let me open the terminal. And let me type Python three. This opens our
interactive shell, and if you don't have Python
installed on your machine, please see the previous video where we were installing Python. I've got my interactive
shell and I can print. This is the function
that we can use in Python to process the data
within those brackets. So if I just type hello world, there's not much to process. It simply displays
back hello world. However, there is
another function I wanted to show you
and it's called type. At type, we just replace
print with type. This is a function
in Python that shows us what data type
it is for Python. So if I click Enter,
you can see STR, which really means
string simply. So string are all those
characters here inside the quotes and note we
included the space as well. When I click Spacebar, it's still considered
a special character. It can be part of the string. If I try to check
how Python sees, for example, I don't
know, whatever. These some numbers and then some special
characters as well. If I click Enter,
it's still a string. So even if I put the numbers
or special characters, as long as they are within either single or double quotes, it will be still a string. Let's try now some numbers. Type maybe ten. Now, Python considers
that as an integer. We have only INT, but that
means really an integer. Now if I try the same
with let's say -200, that's still an integer. And if I try zero, Python still considers that
this data type inside, it still considers
it an integer. Let's jump to floating
point number. If I type 2.5, now we have float. The full name for
that data type in Python is floating point number. Anything that has
that dot notation is really a floating
point number. Because if I type 2.0, note that it's still a
floating point number. But if I type just two, now we've got the integer. So it's not really about the
value that is stored there, it's about the notation. If we've got that dot notation, it will become a float. If there is no dot, it's
considered an integer data type. But now let's go a
little bit further. What if I type, maybe
print first to see the output five
times hello world. What will happen? What do you
think? Let's click Enter. Python simply displayed string that string because we've
got those quotation marks. I displayed that
string five times. But what if we now check
what data type it is? If we use type function, what do you think we will get? Let's click Enter, and it shows us it considers it a string, which makes sense because
it's very long output, including some spaces, but
it makes sense, doesn't it? It looks like a
string. It's simply now much longer string. It multiplied string five times, so the output is still
considered a string. What if I do now type 5.0? I'm trying to multiply
five times hello world, but now I will use floating point number rather
than integer. Let's click Enter.
We've got type error. Python tells us, I can't
multiply sequence. Sequence, it means
really that string. I can't multiply it by
something that is not integer. You can't multiply it
using that dot notation. And that's really important
to understand because there are some operations
that are allowed in Python, and there are some operations
that are not allowed. Because consider a situation
where I'm trying to do, let's say, I don't know,
5.77 multiplied by hello. That would also make no sense. I mean, this notation
actually makes sense, but Python simply refuses that operation because it can see the floating point number, and it only allows for that
whole operation as long as this part is integer and
not floating point number. So there are some
limitations that we have to understand
within Python. Somebody might think, Okay, but for example,
this is allowed. Print -200 is integer, isn't it? So I should be able to
multiply using this operation. If I click Enter, well, there is nothing displayed
because it's negative number. But if I check type of that
output, Python doesn't mount. It says, it's
string, even though, you know, it's nothing there,
but this will be allowed. Same with zero. Still fine. Let's check a few more examples. Let's do print two by two, maybe spices here,
easier to read. We've got four. Let's print two, multiply by 2.0. So
we've got integer. And we've got floating
point number. If I click Enter, now we've
got 4.0. Why is that? Because result of this, if we multiply one integer
by another integer, the result is still an integer. If we multiply integer by
floating point number, the result will be
floating point number, and we know how to check that. We can just use
that type function. So if we do type two by two, we can see it's integer. If we do type two by 2.0, we can see the result
of that operation is considered by Python as
a floating point number. What if I do print two by
this? What do you think? Now, this became a
string because dot is also a special character that can be a part
of the string. What Python will do now? Click Enter. You can see it's called string
concatenation. It simply displayed this
string twice, 2.02 0.0. It didn't do
mathematical operation. It simply displayed
this string twice. What will be the data type as
a result of this operation? As you might have
guessed, in this example, it is actually a string
because this is I mean, this string is similar to this one we had
with Halo world. We did exactly the
same operation here. Only this one made a
little bit more sense. But once we start doing this, it might be not clear
at the first side, but that is not a
number anymore. This now is just a string. So a sequence of characters. So yes, that's really all
I wanted to say today. I just would suggest to play with those data
types for a while, because the better
we understand what is allowed and what is
not allowed in Python, then the more efficient
we will become in the future when dealing with
errors in our programs.
4. Variables: Now I want to talk
about variables. What are those variables? They are not specific to Python. They are in most
programming languages. You can think of variable as
a box or bucket, let's say, where you can store some stuff, and what is that stuff
that you can keep there? It can be loads of
things actually. It can be a basic data
like a single string, integer, or floating
point number. But it can also be some
more complex data like lists or dictionaries or
even entire functions. All that stuff can be stored in that variable or in that box
or bucket as we call it. And as if we do with
the bucket or a box, we can store some
stuff, but later on, we can take this stuff out
and put some other items in. Let's see exactly how it works. This is my Ubuntu, and I
will just open terminal, and we open interactive shell
with Python three command. I will write something like
X, equals, string, Mek. So I've got double
quotes, so it's a string. And what I did here, well,
I have to click Enter. Now, what I did, I assigned
that value, that string, Mk to variable that I called
X. That's all we have to do. We have to type the name of the variable and then what
we want to put there. So I can make another variable, maybe Y, and it will be
equal to one, two, three. Let's make yet another
one that equals, let's say, 500 or 500.5. Now when I print value for X, it will show me
that this variable X stores string
of characters RK, and we know it's string because we remember
the function type. If we do type X, Python
remembers that this is string. The same if I do print, Y, we've got the other value. And then we can also do
mathematical operations. If we store, for
example, integer and floating point number, I can do things like
print Y plus Z. That gives me six to
3.5 because it added what's inside Y and
what's inside Z variable. We can also multiply
integers by strings. So if I do print, Y multiplied by X, I will have string Mek
displayed 123 times. But what if I now
change those values? These are called
variables for a reason. I can simply put there
whatever I want. So maybe let me clear
that and I will now say X equals one, two, three, but it's in quotes. So this will be a string, and Y will be, again, maybe 500.5, but it
will also be a string. If I print it now, X plus Y, Python will do string
concatenation. It will take those characters, one, two, three, we'll
display them here, and then we'll add
those characters, string of characters,
which we can see here. And if we do type X plus Y, we now can see this is no longer integer or
floating point number. This is treated as a string. The other thing I
wanted to say about variables is that they
are case sensitive. If I put ABC equals Marek. And ABC lowercase
equals one, two, three. Then if I print ABC, it will give me something
different than if I type ABC lowercase. Okay, let's press
Control L again. We will clear that out,
and I will tell you a secret which helped me
a lot with variables. Let's say we have
something like that. X equals 100. Then we write X
equals X plus one, and maybe some of
you will say, Mark, that doesn't make any sense, but in fact, it does. If we print X now, we have 101 because we can't really treat this as
mathematical operation. What we do here and what made me understand what's
going on here is to read those instructions
from right to left rather than from left
to right, as we normally do. So we take 100 and then we
assign that 100 to variable X. So we read first
what's on the right. It's 100, and then we put it
in our box in our bucket, and our bucket is called X. And then what I do
in the next line is completely
separate operation, but I will read it
again from the right. I take the current value of X, I add one to that value. So I've got 101, and then
I repeat the operation. I take that 101 and assign it
as new value to my bucket. This is my new
item in my bucket, and the third line is again, completely
separate operation. I print the most current value that I store in my
bucket called X, and it's one oh one
there right now. So if I repeat it again, now, you might have guessed, I will have 100 too. So once you start reading them from right to left, then, well, at least for me, it
made it much easier to understand what's going
on, the entire process. And I think that's all for now, make sure you understand it very well before we
progress even further. Thank you.
5. List and Index Position: In this material, I want to discuss yet another
data type in Python, and it's called a list, we've already learned about
variables and how they can hold information like
integers or strings. Let me open the terminal. Let's open interactive shell. For instance, if I
declare X equals Marek, and Y equals one, two, three as an integer, then I can retrieve
that data by using print X or print Y. However, storing just
one value per variable can be very inefficient and challenging in
certain scenarios. Thankfully, with
lists, we can store multiple values in
a single variable. I can write something like this. First, maybe Marek. Then we could add that 123, maybe I don't know,
500.5 we had previously. Now again, one, two, three, but as a string this
time because it's within the quotes and maybe also 500.5, but also as a string. We will enclose it in
brackets in quotes or again. Here I have five different
pieces of information. Ideally, I'd like
to keep them all in one variable rather than
creating five separate ones. Sure, with just five values, it's not that challenging. But imagine if I wanted to store 100 or even 1,000
different values, creating separate variable for every single item isn't very
efficient or very clean. This is where the last
data type comes in handy. What I can do now, I can enclose all those values that I need
inside the square brackets. And then use commas
to separate them. I can include or mix and
match all data types, as you can see, because
I've got here a string, here is the integer. Here we've got floating
point number, et cetera. They can all be
in the same list, and now we can assign
all those values to one variable called X. I
mean, I will just call it X. And once I hit Enter, all that information is
saved in my variable. So if I print X now, I can see my entire list. However, displaying all that
information at once isn't usually necessary or isn't what we really want when
writing a program. Typically, we only need a
specific data from that list, maybe one item or
maybe a few items, but not the entire list. This is where index
position comes into play. An index position is simply the current position of
each item within our list. It's important to note that index positions start
from zero, not one. The first item in our list, string MA we'll have an
index position of zero. Then the second item will have an index position
of one and so on, which means our list has what? One, two, three,
four, five items. But the index positions will start from zero and end at four. This will be index
position number four. The question is, how can I retrieve a single
item from that list? That's exactly what an
index position is for. So I can do something
like print X, and then I just use
its index position. Let's say I want to retrieve the first item,
Mek, string Mrek. It has index position of zero, so I add exactly that. It's index position
in square brackets. If I presenter, I've got only
first item from my list. As you can guess, if I use
index position number one, I will actually get second
item from the list. It is a bit confusing, but
you can get used to it, and my last item in my list will have index
position number four. So I have to use four. I can also perform
some, let's say, mathematical operations as
we did with single items. I can do something like that. This is the item with
index position number one, which is 123 integer, and I will add again
the same item. We should have 246, 246. If I add, maybe here we
change to last item, and this one will
change to first item, I will have Mark
500.5. Why is that? Because they are both strings, Mark and this 500.5. This is enclosed within quotes, so this is read by
Python as a string. Python performed
string concatenation, it displayed Marek and then
added those characters. It simply created longer
string of characters. But now interesting
thing is I can also count from end of my list
towards the beginning. I just use negative numbers. Minus one, index position minus one is the very last
item in my list, it should be 500.5. Second item from the end of
my list will be this one, one, two, three,
but this is string. It's not integer like here, so we can check that. We can also double
check the type, which indeed is string. More thing I wanted to mention, we can also pick multiple items. For example, we can do something like that, colon and two. What I do now, I want to
retrieve all values from my list that go from zero
up to index position two, but it will not include
that index position two. To make sense of that,
let me click Center. This entry means go up to index position two,
but not include it. It will take index position
zero, we display it. It will take index position one, will display it, we'll go
to index position two. But this notation says do not
display index position two. But if I do something like that, I will remove column here and
we'll add it after the two. This means go from index position number two to
the very end of the list. If I click Enter now, this time, index position number two will
be included in my output. So it's zero, one, two, and we can see this item
is included in my output. Then we have one, two, three, and simply it goes up
to the end of the list. These are the very basics of how we can work with
lists in Python. And I would suggest you
play with it as well, especially with this item because it's a bit
confusing, at least for me. And just to double check, we can also do type
for that X now, which shows us that new data
type or data structure, sometimes it's called that it's called list. That's
it. Thank you.
6. Dictionary method: In this material, we
will learn how to use something called a
dictionary in Python. This dictionary in
Python allows us to work with something
called key value per. I know that doesn't explain
much so far, but don't worry. I will show you what
it is all about with examples because that's
probably the easiest way. To explain this, let's think about what
dictionary actually is and how we can use such a dictionary
in our daily lives. Take, for example, an English
to Spanish dictionary. Let's say we want
to find out what is the equivalent of English
word hello in Spanish. So we open our dictionary to the page where the English
word hello is located, and we can see that in
Spanish, it's a word O. And this is exactly how a dictionary works
in Python as well. So that word hello that we're
looking for is our key. We want to translate
that word into Spanish. But at this stage, we don't know yet what is its
Spanish equivalent. So we search for the word
hello in that dictionary, and once we find it, we will discover that
in Spanish, it is Ola, and that word Ola is the second part of
our key value pair. Hello is the key, and the Ola will be our value that
we are looking for. This value represents
the meaning, and it is simply something
we are interested in. This is the value we were
looking for in our dictionary. Means we need to know
that first part, we need to know the key, and we know the
word hello already. We just don't know what is the Spanish
equivalent of that. But since we know what
it is in English, by searching through
a dictionary, we find its Spanish equivalent. So let's create such
dictionary in Python. And since we enter words in Python in quotes
because word like hello or Ola will be a data type string means
sequence of characters. So we write something like Hello in quotation
marks as a string, then column and then quotation marks again
for another string, and that other string is Ola. So we write the key, the column, and the value, and maybe we want to add more
key value pairs. What else should we add? Maybe we will add
the word goodbye. What we have to do, we will
separate that with the comma, and now another per. Goodbye, and we will type it Spanish equivalent,
which is Adios. Maybe another one,
let's say apple, but we will separate
again with the comma. Comma will separate
each key value per, and now another entry will be Apple then colon
and what its value. And in Spanish, it's manzana. And maybe one more,
I don't know, bike and in Spanish, it will be Basileta
we could carry on. We could enter as many keys like these hello and O
key pair values. We could enter as many
of them as we want. We can even input all possible
words in both languages, creating our own full
English Spanish dictionary. All right, but how
do we access a value for a given key now in
this dictionary in Python? In the book, we open to the page where the word hello
is and that's it. So how do we search for
that word in Python? There are many
possibilities here. Let's look at a few of them. First, it would be nice to
save it as just one variable. Our entire dictionary will be
saved as just one variable. Remember how in the
previous episode, we saved the entire long
list as variable X. Here we can do the same.
But to save our dictionary, we need what's called
curly brackets. So we saved our list
using square brackets, and here we need to save the dictionary using
that curly brackets. It's curly bracket at the end, curly bracket at the beginning. Then we can just
save it as X equal and all those entries that we want to keep
in our dictionary. Let's just click Enter
and the question, how do we search
that dictionary? First, let's try to let's see what happens when we
just print the X. As we can see,
Python will display the entire content
of the dictionary. That is all the key value pas that we have saved in
it. Well, that's nice. But if we save
20,000 words in it, let's say, that won't be
very helpful, will it? So let's search for only the word that we
are interested in. Let's type again, print X. And now, just like in the
previous material on the list, where we enter the index
number, for example, print X and index position one, here, instead of
that index number, we will enter our key. Let's say we search for Hello. What will be the Spanish
equivalent of hello? So we will paste here in
quotation marks still Hello. And now when I press Enter, we see that it shows us
the value for key hello. This is the information we are interested in from
that key value per. The key is our English word hello and the value is
its Spanish equivalent. O. Now, let's say we
want to find out what the English word apple is in Spanish. We do
exactly the same. We can do the arrow apple
and we know it's manzana. But I mentioned other ways
to work with dictionaries. The alternative way would
be to use something called a method and what
that method is anyway. In short, I can say that
both lists and dictionaries, they will both have
something called methods that might help us to perform certain operations on these lists or dictionaries. To check which methods
are available for us, we can enter
something like print. Then help and then
the data type, which is dictionary, the ICT. It will display us help
regarding dictionaries. So if I press Enter,
you can scroll down. You can see get method. For example, there is another
one called items, keys. We also have values, but let's maybe
return to our task. So I can use a method
by writing print again. A X, then dot G. That's
our method we want to use, and then in the
brackets word hello. That will display us also
the Spanish equivalent. But how did I know to
put it in the brackets? Maybe, let's go back, sorry. If we go to that
help to get method, and these are the
possible values we can use in that bracket.
You can see the key. And if we use the key inside
the bracket, it says, return the value for the key if key is in dictionary,
else, default. Basically, I need to put my key. What is my current
key? I'm looking for. But someone might
look and say, Mark, this is exactly the same what we wrote without this method. We got exactly the same
thing when we printed this above in square brackets. It's exactly the same output. And at the first glance, it might indeed seem so, but using methods has a significant advantage
in programming, especially regarding
how it handles errors. Let's say I type
something like print X, but hello, maybe I mistyped it. I missed one L in our key. Now in a presenter,
we can see that Python throws out
something like trace back, mouse, blah, blah, key or hello, it looks messy, doesn't it? But now let's do the
same but using method. This is our method. And again, let's say I have missing
L and press Enter. Now we simply get none, which is the notification that such key does not
exist, and that's it. And if it's part of
a longer program, this kind of output
is much cleaner and much more predictable than
the previous messy one. If we look back at the Python
help regarding this method, we search for if we use
the help function again, if we scroll down, you can see where this non
is coming from. If we type the key and the
key is in the dictionary, we will get the
value of that key. But if the key is not
in the dictionary, it will return that
default option and default equals none. That's why we get the non
response from Python. But I started from the pretty difficult
one, to be honest. We also have those
keys, those items. We've got values and look at that nothing is actually
needed in the brackets. Same here, keys or items. Don't have to put anything
inside those brackets. So maybe I should have
started with those ones. Here. Let's go back, pressing Q. And now let's do print. Again, X dot, maybe keys first, Keys and then brackets, but nothing is needed
in those brackets. IpressEnter and Python returns all the keys that we have
saved in the dictionary. So you can guess if we
change it to values, we will only get the values, which is the second part, yes. These are basically
all the English words we have in our dictionary, and these are all
the Spanish words we have in dictionary. Let me clear that
Control L. Let's get my C. Now let's trade that
other function called items. We change again that
method to items, plus Enter and Python
displays pairs of key values, but each of these pairs is
in separate parentheses. This can be very useful if it's part of the longer program. As an exercise, let's maybe create a different
dictionary at all. Maybe this is the
information about the car that I used
to have years ago. I want to keep information
about it as a dictionary. So I can do something
like car equals curly brackets and then all the information
about that car. Let's say brand was Volkswagen. No, comma, that's
the first key value per brand is the key. Volkswagen is the value. Now the second information,
second key value. Let's say model and the model, it was Passat Volkswagen Passat. Now, another one, maybe, it was manufactured
and it was 2002, and maybe how many miles it had. It had 120,000, if
I remember right. As you can see, in
the dictionary, you can store not only strings, but we can also store other
data types like integers. We have here two integers. The year is 2002, and the miles, the
value is 120,000. But as you can
remember, integers, we don't use quotation
marks for them, neither here nor there. So now I save it,
pressing Enter, and then I ask you to practice
with this new dictionary. If we print car, that will give us all
information about the But now try and use that other ways to access the key value pairs or
individual key or value. So maybe car get model, and I will let you do the
rest just the way we did it in previous example with the English
Spanish dictionary. I hope everything will become
clearer when you complete this task and when you approach it yourself. So thank
you for watching.
7. 'for' loop: This video, I wanted to
talk about something called four loop in Python. Maybe instead of trying to
explain what it is with words, it would be better to simply
look at some examples. Let's open our Python again, the interactive shell, and let's create a list with six elements. And it can be one, two, three, four, five, six. Now let me create a four
loop for those items. So I will add four I
in and now our list, what it does, you will see shortly and we will discuss it. But for now, let's just write
it four I in that list. At the end, we will add
colon and we press Enter. Now we need something
called indentation. So you have to press either tab or you have to press
space multiple times. I will press Tab, maybe. Tab will create like
four spaces for me. This is called indentation. You have to start further. Not this free space here is
the indentation. All right. We write print I. Now press Enter and you will have to press
Enter one more time. You have to press Enter twice because if you press just once, Python will think that
you want to write yet another line rather
than execute the program. We press Enter twice, but what we have as a
result, as we can see, each of the elements we had in that list is displayed
now as a separate item, and each of those items
appear on a new line below. Let's think about what
exactly happened here, what this four loop did exactly. I think it's easiest
to understand if we read this
instruction backwards. I mean, this is the instruction, first instruction for I in one, two, three, four, five, six, what this four
loop first checks, if this object, it will check
if this object is iterable. Iterable means it's anything
that it's something that can return just one element at
each iteration of the loop. Or in other words, this checks whether it can break this entire object
into smaller pieces, giving us just one
piece at a time, one element that we can work
with on each next iteration, it can provide us with the
next element from that object. This situation
occurs here because this list of many elements
can be broken down into individual elements
and each of our numbers in this list is indeed such
an individual element. So once this condition
is met, I mean, this object is something that four loop is able to work
with in the first place, then that four loop
starts its work. I first selects the first
element from our list, which is the number one and
assigns it to our variable I. Because what we have here
after this four statement, is a variable that we can
name however we like. I happen to name it the single letter I just so I wouldn't have
too much to write, but you can call it
whatever you want. In this first so
called iteration, which means the first
repetition of this loop, we simply have I equals one, and now we can do something
with that variable I. Simply just displayed it
using the print I statement. Let me repeat. Let's
not that this print I is indented and
it's very important. This indentation happens
that Python will know that this print function
is considered to be inside of our four loop. Everything we do here like
we print this variable, is the first iteration, the
first repetition of our loop. This is the task
we give Python to its instruction what
Python has to do with this variable
and we just print it. So that loop did what
it was supposed to do, but then it goes back and checks if there are any other
elements in this object. And if there are, this four
loop will pull it out for us. And such an element exists,
it's the number two. So now the loop assigns the value to our
variable I and again, performs the operation or operations because you can
have multiple operations. We have just one. It's
a print function. It simply performs
that operation for us. So it prints the variable
I again, but this time, our variable has the value of two instead of one,
as it did before. I displays two, it then goes back and checks
one more time. If there is yet another
element that can be pulled out and assigned to the
variable that we called I, and it does it six times. After the sixth time, it again
goes checks the object and it sees that all
the elements from our list have already been used. So at this point, the loop
has completed its task. But now let's take
another look at our loop. Our entire list with those six elements
can also be saved as a variable because we
can write something like X equals then one, two, three, four, five, six, I press Enter. Now we can create
the loop again. But this time, we will notice that we will have two variables. We can have four I in X, and now I press Enter once. Click cab to create indentation,
and I print that I. First variable is
that I that will be grabbing each individual
element from our list, but the list itself
is also a variable, and it's our second
variable, which we call. So now press Enter, Enter, we can see that we get
exactly the same result. But as I mentioned,
inside this loop, we can also perform operations on each
of these variables. I mean, it doesn't have
to be one operation. It can be multiple operations, but let's create
maybe a simple one. So I will write for I in X, Enter indentation with tab, and now what I will do, I will multiply our variable by itself. So it's I multiplied by I. Let's press Enter, enter, and now we can see that
in the first iteration, when our element is one, I mean, our variable I has value of one, we get the result for
one multiplied by one. Then next iteration, our
variable will have value of two. So our displayed result will be for two
multiplied by two, and we can see it
repeats until we reach six multiplied by
six, which is 36. And as I mentioned also, we can name that variable
however we like. I was just lazy calling it I, but we can call it
Marek, for example. Let's do four Marek in X. Enter. Now tab to
make an indentation. But now I will print, I have to use my new variable
name, which is Marek. I now multiply Marek by Marek. Press Enter twice, and again,
we've got the same result. Let's press Control, maybe,
let's clear that out. One more thing I wanted to
mention is that the list is not only the type of data
we can work with here. Another type of data that belongs to those iterable types, for example, is a string. We can write something
like four I in. Hello, column,
Enter, tab, print I. Now we can see that
the loop can also break a string into
individual characters and present each one separately in next iteration in the
next repetition of the loop. But, I think at this stage, I think it should be enough
to know about the four loops. So I will see you in the
next video. Thank you.
8. Python break continue statements: Now I wanted to mention the so called break and
continue statements. What are they and how
they are useful to us? In previous video,
we learned about the four loop and how it can iterate through the items
in the list. So just recap. We can have a list of items one, two, three, four, five, six. I will save it in
variable called X, and now I can do four
I in X, print I. But let's say I want to find a specific
number in my list, and maybe when I
find that number, I want to announce it somehow and break all
subsequent iterations. Or simply put, since I found
what I was looking for, my loop has completed its task. That's exactly where the break
statement is very useful. Let's write something like that. For I in X, create first indentation,
I press tab one. I will write something
like I I equals four, and I know we haven't
talked about it yet, but this is basically
how you can check if something
is true or it's not. So here I'm checking
if I is equal to four. But note, I have to
press equals to twice. Yes. We will talk
about it later. Now, I press Enter again, and I press tab twice. So what I mean, my indentation
has to go even further. And now I say maybe print
number four. Has been found. Press Enter, match the
previous indentation, I press tab twice, and now I say break. Press Enter, and
now I will create one indentation
at the same level as the previous I statement. And now I say print I. Let's press Enter twice now. Now as we can see, this loop works normally for the
first three elements. It displays one, two, and three. So my loop takes the first
element, which is number one, assigns that value
to my variable I, and it checks if I
is equal to four. But because it has number one, it can see that it's
not equal to four, hence it skips that more
indented elements and goes straight to the line that is at the same
indentation level, which means it simply
prints element I. Which is one. Then it goes
back to the beginning, pulling the next
element from the list, which this time is
the number two, and it repeats this process, checks if it's equal to four, and if it's not,
then it will simply ignore those more
indended lines. Goes through the
loop again, it has three and then
goes back and goes through the loop again until it pulls number
four from the list. Now four becomes my variable I and it can see it
does equal to four. Since this condition is met, it looks at what it
must do in this case. I will check this time
these more indented lines. It sees that this time, it has to display something
different on the screen. It must show us the string
number four has been found. And that's exactly
what we can see here. But in the next line, it can see the break statement when the loop sees this command, it simply stops its operation. It simply knows that whatever
had to be completed has been already completed and
the loop is now terminated. That's how the break
statement works. But there is yet
another statement, and it's the continue statement. It's very similar to
the break statement, except that the loop does
not stop but continues until it completes
all the iterations over all of the
elements in the list. If we change that
break to continue, let's write it
again for A and X. I X equals four,
everything the same. We say print, number
four has been found, but this time, I will create two indentations and
I will say continue. Print I and press Enter twice. And this time, we can see that for number four,
instead of the number, it prints string number
four has been found, but it does not
interrupt its operation. The four loop keeps going. It checks all the elements in the list until it has
gone through all of them. And sometimes it is useful
if you, for example, have multiple items in your list with exactly
the same value, and maybe you want to know how many you have them in that list. Every time the loop
will encounter four, each time it will display that string instead
of the number four. I mean, if we change our list to something like X equals one, two, three, four, five, four, two, four, let's
run our loop again. We can see now it found all elements that
have value of four. And I know that's for
a short explanation, but at this stage, it will be all that
we need to know regarding the break and
continue statements. So thank you for watching.
9. 'while' loop: Previous materials, we
saw how four loop works. We saw that four loop
allows us to extract each single element from a more complex
object like a list, and it allows us to perform some operation on each
of these elements. For example, if I have
ten elements in a list, then the loop will be executed
ten times and that's it. However, there are rare
situations where we do not have a strictly
defined number of elements and we need
a loop that will keep running until a
certain condition is met. Trying to explain this in words usually doesn't make much sense. Let's do it through examples. Let's create
something like this. Let me press Control L, and I will say X equals one. Our variable X is
a simple integer. But now I say, while
X is less than ten, Enter and create indentation
with tab, print X. Now another line, indentation, X equals X plus one, and I will click
Enter twice now. And we can already guess
what that loop does. So initially, we have our variable assigned
a value of one, and then we have our
loop, our while loop. We say that while X
is less than ten or perhaps as long as
X is less than ten, execute all the
instructions below, and the loop executes
our instruction, which here simply displays
current value of our variable. However, that last line
might be a bit confusing. Someone might look
at that and say, what it's supposed to mean? How can X equal X plus one? First of all, let's not think
of it as mathematical task. Remember that X is our variable, and in the case of variables, it makes more sense to read
this from right to left. But our variable starts
here in the first line and we've got value of
one assigned to it. But then we take that
current value of variable X, which is one, and we add
some other value to it. And here we are just
adding another one. So we have two together. Now this new value,
this integer two, it's now assigned again to
variable X. X is now two. Our variable X now
has a new value which is two and the L
loop starts over again. And checks whether
that new value of variable X is less
than ten or not. Well, it's two, so
it's less than ten, so the condition is not met. So the loop repeats again. The new value of variable X is passed to the print function, Python displays two this time, and so it goes until the
value nine, as we can see. In this last round,
let's call it that. The loop again checks if
nine is less than ten, and it is less than ten, the condition is met, so the loop repeats
again one more time. But this time it
takes this nine, then we add one to it again. And we save this result as the new value for
our variable X, which is now ten. Now when the L loop checks
this new condition, it sees that this
time the condition is not met because ten
is not less than ten, but it's equal to ten. That means its work
is now completed. The lo has executed actions on all elements that met
the initial condition, but it is abandoned as soon
as the condition is not met. It's also worth noting
that the first X equals one has no influence
on our loop at all, later on, because this is just initial value
of our variable. But later during the
execution of the loop itself, the loop repeats within itself. It doesn't go back
to the first line. The loop starts at second line. What we recorded earlier as the initial value
is only read during the first repetition of the but in every
subsequent iteration, the last line sets a new
value for our variable X, but the first one is no
longer considered at all. But that well, we often see that last line written in
Python in another way. Let's write something like this. Maybe X, this time will be, I don't know, 100. Now we say le X
is less than 110, print X and then X plus
equals one plus twice. If we look at this
notation in the last line, it makes even less sense, but this is simply a shortened form of exactly
what we wrote before, which is X equals X plus one, and we see if we run it now, basically the logic
is exactly the same. For the time being,
that's all we need to know about the i loop, so thank you for watching.
10. Python true false boolean: Python, as well as in other
programming languages, we have something
called a Boolean, and this boolean, in
addition to its funny name, can have two values, and they are so called
true and false values. And as always, let's
take a better look at examples of what I'm talking
about and how this boolean, be true or false can help
us in Python programming. This time, you know
what? Instead of doing it in interactive shell, let's maybe get out of
it and exit function. Clear. And we will write
and save it as a file now. We will create a
file or use VIM, maybe Marek dot pi. That will be our program. And we can write something
like X equals one. And now while X
is less than ten, column enter, and you can see VIM creates the
indentation for us. We don't have to press tab here, and I know by now, some of you might think, Mark, have you ever heard of
that thing called IDE? Yes, yes, I heard about it, and don't worry,
we'll talk about it, but we'll talk about
it much later. For now VM is okay. So we've got that,
and now we print X. And again, we do X
equals X plus one. Or in previous video,
we already so we could also write it as X
plus equals one. It's basically the same thing. Let me save it to save
in VM IpresEscape, column WQ, and now I
can run my program. I run it by typing Python
three, mac dot py. Now we have something
that we've seen before and the result
that we expected. But what if I change
that initial value of our variable to ten or more?
Let's open the file again. So what I'm saying,
the first line, let's change it to 20. I say X equals 20, and then the first
iteration will be while X is less than ten, but X is 20 and 20 is
not less than ten. It's more than ten. But
let's see what happens. I press Escape, Colm WQ
to save that new program. I can also cut it. We can see
our program. Let's run it. I press Enter and
we run our program, but nothing is displayed. Why? That's because in
that very first line, we set our variable
to hold value of 20, and then the loop checks on the first iteration whether
this condition is met, if X is less than ten. I 20 is less than
ten, no, it's not. Since 20 is not less than ten, the condition is not met. That means the loop gets
this bull value of false. So it doesn't execute
even one repetition, not even one iteration. Simply already on that
first line of Wil loop, this loop is abandoned. However, there are
situations when we want the loop to execute
at least one repetition. And to do this, we need to
change our program slightly. So let's rewrite the
first line first line of the Willoop I mean. And now I say While through, and I leave that print X. I
will do further checks below. All right, so what I'm
saying here is I forced now the loop to perform at least one repetition
because we told it, you have nothing to check here. The condition is already met. I'm saying you while true. So there's nothing to check. I'm saying you that the
condition is already met. Doesn't matter what it is. And first iteration
must be executed. Therefore, the loop,
whether it wants it or executes everything
what's below, and it reaches the first line where we have our condition, but I changed it slightly. It checks now if X is
greater or equal to ten, and in this case, it is
20 is greater than ten. So the loop will execute whatever is in even
more indented lines. It will print that number
is too large and below, we can see the break statement that we saw in the
previous videos. So we know that this loop will simply be abandoned
at this stage. But maybe let's see how
it works. I will run it. We forced that first iteration. We can see it was printed, the 20 was printed because we forced
that first iteration. But now let's change
that initial value of X to something smaller. Maybe let's clear
that. Let's VM Marek. Now let's say X
equals maybe one. What it should do now, it still has that first iteration forced, but because this condition
will not be met initially, these two lines will be omitted. These two lines are only considered if the previous
condition is met. But one, for example, one, one is not larger or equal to t. I will repeat the process of X of increasing the value of the variable X until
it reaches that. Well, maybe let's run
it, should be easier. Python three, Mark Pi. What is important here if we force this bullion
for the Wile loop, we have to break the
program somewhere else because otherwise it will run forever and
we break it here. So even though we force
the first iteration, we don't have to
worry much about it because we break
it somewhere else. But what happens if I didn't have that
break statement here? Let's have a look.
If I remove it, now we basically
have nothing that would stop this Wil loop. So let's save it. Let's run it. And now we see the
number is too large, but it doesn't really
matter because there is no single line that would
force this wile loop to stop. There is no break statement. Let's Control C, maybe. So I have to stop it like
that using Control C. You can see it
counted already to over 3 million. So
that's basically it. That's what bullion
true and false are, and this is how I can use this bullion to force
iteration for the Wil loop. I hope that makes
sense. As always, I recommend not only
watching this material, but also experimenting
on your own to fully understand how it
works. Thank you for watching.
11. Python f-string: In this video, I wanted to talk about something called F string. As usual, I won't try
to explain it in words. Let's get straight to
the examples to see what it is and why
it exists in Python. Let's say I have a variable. Let's call it X, and the
value will be string mac. What I can do now,
I can run print. I can say hi, maybe I will
add spice and then plus X. And if I run it now,
we can see that Python adds those two
strings together. So the first string is high, and we know it's string
because we've got it in quotes and Python knows that
this is string data type, and the second string is Mek. But that second
string Mrek is read from the current value
of the variable X, though, which means
Python looks at that X and says, Uh huh. The second part
is not in quotes, so it must be some
variable then. I must find that variable and check what is currently recorded in that
variable called X, once Python finds it, only then it
displays the result. It's worth to note that when
it finds the variable X, it checks also its data type. Since Mac is in quotes, it knows it's a
string data type, and ultimately, Python
displays that high mark. This whole operation, when we
add one string to another, is called string concatenation, and we have done such
operations before, so it's nothing new for us. But let's do something
different now. Let's type height equals 178, it's in centimeters and weight equals 93.5, and
it's in kilograms. But that doesn't really matter. And what I'll try to do now, I will try to use that
string concatenation method. So I print So you've got print, your height is in quotes, as it's string, I will try
to add that height variable, and then I add another
string and your weight is, and I will try to add
that weight variable. Let's click Enter.
As we can see, Python is complaining, and it even tells us exactly
what it doesn't like. It says, You can
only concatenate string to string,
not to integer. This makes sense because even this entire operation is called string concatenation, which means adding
some strings together. Here, what is the first
value we try to provide? What is the first
variable? I mean? Well, it's an integer. It's the whole number 178. In the second case, we've
got floating point number. I can tell you right away
that it would also complain about it because it's floating point number
and not a string, but because Python encountered
that integer first, the error only
mentions that integer. We simply cannot add those
two data types together. Theoretically, we can fix
this in various ways. For example, we can
write our values as strings by simply adding
quotes around them. My height because this and
my weight becomes this. And if I try to run it
again, now it works fine. Since your height is 178
and your weight is 93.5. That's because we changed the data type for height and weight. But the thing is,
what if we want to keep our variables as
previous data types? I want to have that integer
and floating point number. I don't want to keep
them as strings. So let me convert them back. And the other option we have, we can use STR function, which can change the data
type of current variable to a string regardless of what
data type it currently is. So I've got my variables
back to what they were integer and floating point, and now my print will look
a little bit different. I will change this height to
string using STR function. And because it's function,
we use those brackets, and then I go to
weight and I convert weight also to string using STR. Function. Let's run it now. As we can see now
it works again, even though the
variables are kept as integer and
floating point number. We only change them once
for that print function, but it doesn't
change the data type of the variable itself. You could say, Hey, it works. Yes. Yes, it does work, but it's a bit tedious
process, isn't it? We have to look for
all those variables, check which ones
aren't strings and use some functions to convert them
to strings if they aren't. This really isn't
that clean, is it? So there is another function, sorry, it's a
convenience feature, I would say that was added, and it's called F string. And I believe that
F string comes from the format string because the syntax is similar to that format string method
in the Python versions. So how do we create
that F string? We simply I will
use up arrow again. So this is our last
print function. And now, will just move it to the very beginning
and I add little F. And now I don't have to change any data
types with function. Python will do it for us
automatically if I just enclose those variables in
so called curly brackets. This is my first variable
I want to convert. I use curly brackets here and the second one
is the weight. And now I also don't need
these quotation marks. Because Python will convert
those values to string first, so it will be a very long
string of characters. I have to add quotation mark at the end because otherwise, all of that is simply
one long string. Now, if I presenter, then you can see that I
did something very stupid because I can also get rid
of that plus. That's better. But now look at this syntax
and look at that syntax. I think this one
looks so much better. In fact, you'll encounter F strings very
frequently because also this process called
string concatenation is used very often, I would say in Python. That's all I wanted to
say about F strings. It's essentially
just a convenience, but it is very
important and it's commonly used feature in
Python. Thank you for watching.
12. Input function: Now let's talk about
the user input or the input
function. What is it? User input is a function
that allows the user of our Python program
to enter some data. Let's take a look on how
we use this function. This is what we did
in previous lesson regarding the F string.
But I will copy that. That might be useful,
let me just exit. Maybe we will write a
little program this time. A little VIM, and we'll
call it Mac dot pie. Ah, okay, I already have
Marc dot py program. Never mind. We can reuse it. We just delete everything here. I will paste that line and
I will add that height. That was in centimeters and the weight that
was in kilograms. This is our program, so I will escape column WQ.
I will save it. And if I run it now, we have
exactly what we had before. Python displayed what we had already seen
in previous video. But what if our user wants to enter their individual
data themselves? Because every user will have different height and
different weight. Don't want to have those
static entries in the program. We want a user to be able to type in the values
for the variables. Plus, we need to have some
accessible way to input those variables when
running the program because our users probably
don't know Python. For us, it's not a problem. I can open the file,
change the variable. That's because we know Python, but our user probably doesn't. The input function is
used for exactly that. Let's edit our program again. Then we'll go to Mark Pi
and what I want to do. Is to use input function. Because it's function,
we use those brackets, and in fact, I don't have to put anything in
those brackets, but that's a bad idea
because what I can do, I can put some hints for the
user about what to enter. And for the height variable, the user should enter the height is and preferably
in centimeters. So I can say as a string quotes, I can say here, what is
your height in centimeters? And for the weight, I also use input function in quotes again, and I can ask user, what is your weight
in kilograms? And once the user types that in, that user input
will be then saved as our variable for
height and for weight. So now let's save
it with c colon WQ, and they run the program again. And we can see that
program encounters that first user input function. So the program stops and waits until that input
data is received. So my height is, let's
change it maybe 150, I say, just to put
something different. Now it asks me for
weight, maybe 88. If I press Enter, now our program has all the
variables it needs, so it displays your height is
150 and your weight is 88. If I run the program again, maybe different user runs it and they have different
height and weight, maybe 201 hundred, the
result will be displayed for these new variables or for the values kept in
those new variables. As always, I recommend
not only watching this, but start playing around
with those functions simply to remember them and understand them better.
Thank you for watching.
13. Python Functions: In this material, I wanted to talk about functions in Python. In fact, we have already
encountered several functions. Probably the most
popular function that we used almost every time
was the print function. We can do something
like print hello world, and this is so called
built in function, meaning that print function is immediately
available in Python, and we can access it right after installing
the Python itself. There are many
built in functions. For example, the
other one is length, and we just type LN N and it shows us the
length of a given object. For example, I can
do maybe a list. 56789. I press Enter, and we get the
length of that list that was passed to
the LN function. We can also check the
length of the string. It's not a problem if I
type length hello world. It will give us 11 because
that space is also included. It is a special character
that is part of this string. One more function I wanted to mention is the help function. It displays very helpful
information for us. It's called help,
so no surprise. For example, help n. It will show us more information
about that length function. Let's press Enter,
and we can see that length function is
indeed a built in function, meaning it is immediately
available in Python. It's installed
together with Python. Press Q, and we can do, well, maybe the same for
print function. We can also see that print
is built in function. Help will also show us what we can put inside
those brackets. Q again to exit. That's fine, but what if we want to create our own function? In fact, it's pretty easy, let me show you how to do it. Let's maybe exit that and clear. We had a little program
in previous video. It was that one
regarding user input. So maybe let's change this one. Maybe let's change this program. I will say VIM Mark D pi, and now maybe I want this print, which is here, maybe I want it to be in the
form of a function. So we can do
something like that. I can define my function. So I type DEF to
define my function. Then I choose a name
for my function, whatever it doesn't
really matter. I will call it maybe F one because I'm lazy and I don't
want to write too much. And after that, we
type parentheses. That's because each function will have to have
those parentheses, and in fact, inside them, I can also add some parameters. We can see here inside
that input function, we can add that string. We can give the
extra information for our user in the
form of a string. That's how you define what can be actually included
inside those parentheses. But for the time being, maybe I will just
leave them empty. We will have no parameters. And now after that,
I just need col. If I press Enter, you
can see that a VM adds that indentation automatically
because whatever I want to have in my
function has to be indented. They want that print function
to be part of my function. Well, in fact, that will be
my entire function for now. So that's it. Believe me or not, but this is our function. Let's save this program now. I press Escape, call on WQ. And let's run this program. I say, Bin three Mark Pi. It asks me my height
17 night, 93.5. We can see it looks like
it doesn't do anything, and that's because we've
got the function defined, but we haven't run. I go back to my
program Mark Dupi, this is how we define function, but we never said to run it. What I can do, I can just type new line here saying F one. That's how I run my function, or you can sometimes
say I call my function. I want my program to run the function that
I've just defined. Let's save it. And
let's run it again. I have to type again
the variables 17,893.5. And now the function
was not only defined, but it was also run
for me. All right. But since we have already the
user's height and weight, let me open the file again. Once we got that
data from the user, we can calculate their BMI. And the BMI, the body
mass index, I mean, simply tells us
whether our body mass in relation to our height
is appropriate or not. Or in other words, whether
we are overweight, underweight, or maybe
everything is okay. So let's first maybe Google
how to calculate the BMI. So we can see we have
to divide the weight in kilograms by height
in meters squared. So for example, a weight of 73 kilograms and
height of 1.7 meters. Our user gives us the height in centimeters,
remember, though. But then it's not
only the meters, it has to be meters squared. Maybe somewhere it's shown
better way like here. We can see it's weight in kilograms divided by
height in meters, and then whatever it
is, we will have to multiply it by itself
because it's squared, or maybe this is even better. That's what it looks like.
All right, let's do it then. And we've got our F one
function, it's fine. We can leave it. Let's define next function, which we should call
probably BMI, I guess. And then the column enter, and we can start defining
what it should do. There is also one more
thing I didn't talk about. It's regarding that
input function. The fact is that input function, whatever we put here, it
will be saved as a string. So height currently will have value of our height
in centimeters, but it will be kept
as a datatype string. So we also have
to format both of them to either
integers or floats. So maybe I will define new variable height
in meters float. Oh, that looks terrible,
but never mind. What I have to do I have to take my current
value for height. So I take the variable height that we already have and store. I run a function called float. This will transform whatever is currently there in
that variable height, it will transform it to
a floating point number. In fact, the same way I can use STR, remember, the string, but it's already string, and I could also use INT to create an
integer out of that. But let's stick to float
because maybe somebody wants to be super precise and perhaps input something
like I don't know, 178.4 for some reason. I want to grab all that data, but I have to store it as
floating point number then. But then one more
thing, remember, we are not interested
in centimeters. The value we have to
provide is in meters. So let me also divide it by 100. If somebody gives me 17 8
centimeters as the value, I will create 1.78 meters. That's exactly what we
need for our calculation. Okay, I think that's
it. Now the weight. In fact, the weight
doesn't have to be we just have to change the data
type, and we can change it. Well, let's call it
differently first of all, float equals float. Well, we have to take the current variable weight
and just change it to float. We will use, again,
function float. So we have two new variables. It's height and it's in meters
because we divide it by 100 and it's floating
point number because we use function float. But for the weight, we only
change the value to float. W. Alright. Next line, we will just calculate that BMI. BMI equals, we
have to take that. We have to take our weight, but as a floating point number. And now we have to divide
it by our height in meters. That's our variable for that, but not only that, it
has to be squared. Remember, we have to multiply it by itself and we will have to add those brackets in that case. Means we grab our
weight and we divide it by height in meters squared. But now, it would
be useful to also print the value as the
output for our user. So we will add that
print function again and we can use
the F string that we already know and we say your BMI is in
curly brackets BMI. We just want to display
value of this variable. Okay. And last but not least, we not only have to
define our function, we also have to call it. We have to run that function. So we say BMI and
just the brackets. We can leave the F one as well. We will run F one function, and then we will run
the BMI function. Let's save it, escape column WQ. And run our program
height one ****, weight is 93.5 kilograms
and the program says, You BMI is 29.5. There's actually one more
thing I want to mention. Let's go back to our program, maybe even two things. First of all, the function,
we create it once, but we can call it several
times in our program. What I mean, if I
run now BMI that, BMI, that, I can call it several times.
Let's run it again. 17,993.5, you can see that function run
three times this time. Maybe let's clear it and
go again to our program. The other thing I wanted to say is that the function has to be defined first before you
call it, before you run it. Let me show you what I mean. Let's maybe remove those
two lines and maybe I want to run a function,
BMI here already. Let's see now what happens. 17,893.5. Python says
name BMI is not defined, which is not really true
because it is defined, but the problem is Python is interpreted
language, it's called, which means it will take every single line and run
it as it is one by one. It checks the weight,
it checks the height. It then check the
function and it can see, but that function at this
stage is not yet defined, it says, sorry, the
function is not defined. Whereas if it would
go any further, it would sit there, but because it's interpreted,
it doesn't do that. That's very important to define all your functions first
and only then run it. It's a little bit longer video, but I hope it's useful.
Thank you for watching.
14. if, elif and else: In this material, I want
to talk about something called IF and sets, conditional statements,
they're called. These conditional statements
are used to check whether a certain condition
is met in a program or not. Maybe let's move to some
examples right away because they are the easiest way to
explain what it is all about. I will create a program, let's call it ILPi I will say X. Equals input, the user input. We already know what
it is, and we say enter the value of variable X. We remember from
the material about the input function that when the user enters anything here, it will be saved as a string. So we need to convert it to
either an integer or float, and I will change it to
floating point number. So I will use
function float. Okay. And now I say if X is
less than five column, then print X is less than five. Now, what I can say is a leaf, which means plus I, it's si, but we say a leaf. I say X is less or equal ten. I will say, then
print that X is 5-10. How do I know that?
Because Python, as we know, will go
from the top down. So it checks first if
X is less than five. And if it was, the program would stop already here because
the condition would be met and it would be printed that X is less
than five, indeed. But if that condition
was not met, the Python will go further and we'll come across
this statement. So we know already that
our X at this stage, if we arrived here, we already know that X
is not less than five. But we maybe want to check
if it's somewhere 5-10, and that's how we can check it. We already know that
it's five or more, so we just want to know if
it's less or equal than ten. It must be if it is, it must be 5-10. And now I can create
another Alif. I can create as many
of them as I want. Maybe I want to check
if it's also less or equal 20. But you know what? At this point, maybe I'm done, and I just want to
say, let's call it LS, and I just use LS. That means for anything else. Well, at this stage, I know that X has to be greater than ten because I know
it's not smaller than five. I know it's not somewhere 5-10, so I can be pretty confident that it has
to be greater than ten. So I can say, print, X is greater than ten. Let's check if it works as we expect it. Say Python three. If else it asks me what I
want to set for my variable, I will say three and indeed, three is less than five. If I run it again, maybe for
value ten, it is correct. It says X is 5-10. If I do maybe 20, it says X is greater than ten. But now, remember in previous
episode about functions. We created a function
that calculates our BMI and the file
should be still here, a reminder, the BMI
was a body mass index, and it's an indicator
that tells us whether our weight is in
relation to our height. If it's within the norm or if it's rather
outside of that norm. We save that file and we can now modify it a little
bit using that IL statements to see to check if our BMI is fine
or if it's not fine. Let me clear that and maybe just as a
reminder how it worked. I type in my height
in centimeters, my weight, and it says, my BMI is 29.5. But is it good, what is it? Let's check first, what is a healthy BMI? What is the norm? I? Alright, so we can see that under 18.5 score is
described as underweight. 18.5 to 24.9 is healthy and
25-29 0.9 is overweight. Then we have also obesity
and severe obesity. Let's use it. Maybe I will
put it here so we can see it. And let's amend our program now. I'll say VM Marek, y we can leave
everything as it is. We will just go to
our BMI function. And now, once the
BMI is calculated, I can use it in the
program to check if that BMI is for a healthy
person or if it's not. So first, I say, I
BMI is below what? 18.5. That's our starting point. So I'm checking. If
my BMI is below 18.5, that means I can use that
print statement, maybe. You can see that indentation is created here
automatically for me, and I print your BMI is BMI. The result, whatever is
under 18.5, if it's 15, 16, then that means
you are underweight. And now maybe let me copy that because that will be
just too much writing. I will yank two lines and I will paste paste, paste maybe again. I think that's okay.
That's my first check. In next check, if the Python
program reached this point, that means my BMI is not below
18.5. It must be above it. So now I will check if it's
between 18.5 and 24.9. Well, in fact, next threshold
is 25 starts from 25. So I can also say here, just if it's less than 25. I believe that's
what they mean, 24.9 9999, you know what I mean? It has to be simply below 25. So that's exactly
what I need, and that would mean I am
in healthy range. You are in healthy range. Or maybe simply you are healthy. Now, next one goes up to 30
because it again says 29.9, but it means to be
below 30 simply. So I say below 30,
you are overweight. Okay, well, that's enough. I will say just
L. But these two, they are not if statements, yes. They are a leaf. You can have only one I and one L. Everything in
between is a leaf, if, and we will
just change this. It's not overweight,
it's obese now. It's either obesity or severe
obesity, anything above. So let's check how it
works, if it works at all. So I run Fon three macular pi, asks me about my hive
once over night. My weight is 93.5. And now I can see
that my BMI is 29.5, but I can also see
that I'm overweight. So if we check that program, it said that I'm overweight. That means I checked if
my BMI is below 18.5. No, it's not because it's 29.5. So we checked the
second statement. If it's below 25,
no, it's still not, and I'm just below 30, 29.5. That means I'm still
in this category. But if I run the program
again for, let's say, maybe I'm 180 and I
weigh 50 kilograms. That means my BMI is 15.4
and I'm underweight. Okay, hope that makes sense.
Thank you for watching.
15. Classes: In this material,
we will talk about so called classes in Python. And in fact, we have been working with classes
almost all the time. We use them in every
previous episode, but it might not be so
visible or obvious. Let's take the simplest example. I will write something
like X equals one. And we now print that X. We simply take the value of one and we assign it
to our variable X. And with the print function, we simply display
it on the screen, and we already know that this one is a data
type called integer, meaning it's a whole number. But how does Python know
that this is an integer? And how does it know what can be done and what cannot be
done with that integer? Remember the type function
that shows us the data type. Let's use it here. As we can see the integer that is a
whole number is a class. That's the very class
we are talking about, and that variable X or that number one are
so called objects. So that value one is an object that belongs
to the integer class, and I can create unlimited
number of such objects. For example, I can
create another object. Let's call it Y, yes. Y equals two. Now if I run same but for Y, this is my second object, but it still belongs
to the same class, which is the integer class. Some of you may have
heard that Python is referred to as an object
oriented programming language, that indeed is the case because
when working with Python, we are practically always working with some
type of objects, whether we realize it or not. If we write something like that, X equals hello world. If we now print
type for X again, now we can see that hello
world was assigned to variable X and it now belongs
to a class called string. That is a sequence
of characters. But what does it really mean? It means that the string class will have different
characteristics. For example, if an object
is in string class, we cannot multiply it by
floating point number. Whereas if an object is
in the integer class, we can multiply it by both another whole number or
by floating point number. So all these rules about what
can or cannot be done with a given object are recorded in the class in which
that object resides. And at this stage, to explain
this even in more detail, it might be the best
for us to create our own class as well as
object for that class, or even we will create
several objects within that new class that we are going to just as we can create
numbers or strings, maybe we want to create
a new class to create, I don't know, rectangles. So yes, let's say we
want to create a class for our rectangles in Python. So how do we create
such a new class? Maybe let's start from
creating a new file. I will use VIM, I will create
maybe Me class dot pi. Now what I have to do,
I just write class, rectangle or whatever
I want to call it, my new class and I add
column at the end. I've just created my new
class as press Enter. Now we can create what's called a properties
for our class, properties and
attributes, actually. What I mean, as we know, every rectangle has a
length and a width, yes. So we can define
those our attributes for our rectangle class. And to do that, we need a special function
called Dunder in. I know it sounds
funny, but it has this unusual naming
because it is written as underscore
underscore, then in it, and then again,
underscore underscore. And this Dunder in it is a
special function that is automatically called
by Python every time we create a new
object from this class, which we will do shortly. Then we also add brackets, and in these brackets, we
provide so called parameters. And currently, the
only parameter we will have here it's called self. I mean, we can call
it whatever we want, but we'll discuss it shortly. Parameter will later
be replaced by the name of the object we
create from this class. I know it's getting complicated.
Don't worry about it. We'll go through it. Same with the self. Don't worry about it. It will be explained shortly. For now, let's write the rest of the things
we have to write, okay? We need those attributes
for our object, which are length and width because that's what
each rectangle has. So let's finish our
function first. We have to just use depth
because each function we write we define by
using that DEF, yes. I keep saying function but somebody to make it
even more difficult, said that if you
write a function inside the class,
it's called method. But never mind, it's really not most important thing here. We have to finish it with
column or function plus Enter. Now we are defining the
attributes, length and width. So we say self width, and maybe it's ten
and centimeters, let's say, leave
ten and self length it's maybe hard coded it to 20. So width of our rectangle
is ten, length is 20. And now to understand
the self what it is, let's create our first object
from that rectangle class. Maybe maybe to make it super clear, I will do
something like that. We finished playing
with our class, we now start with our object. And the object,
how do I do that? How do I create an object? I can create, for example, my first rectangle,
rectangle one, and I just say equals to
rectangle, and I use brackets. And also note, that's
what we usually do. For class, the first letter
is usually capital letter. For objects, it
doesn't really matter, but none of it matters. It's just you can create a class that
starts with lowercase. It's just simply something that software
engineers agreed on. That class should start
with capital letter, and then the remaining
ones are small letters. That's how you create your
first object from that class. What I can do now, I can print
my object rectangle one. I will press Escape column W. I will write it to the file and maybe I will open
another terminal, I will open it here. And I will run that program
to see what happens. I mean, first, let's check if here is where my file is ASL. So we've got previous Mark Pi, but now I've just created
Mark class, so let's run. When we run our
program like that, what Python will display is
the memory location where it created this new object
that we called Rectangle one. All of this, you can see, is simply a memory
location where Python saved that new object. But what really happens
here is Python will read that rectangle one and the first parameter
we placed here, which we called self. Remember, we store parameters
here in those brackets. First parameters
self, Python will replace that self
with rectangle one. I will place rectangle one here, and then it will replace also these with that
value, rectangle one. Rectangle one width is ten, and rectangle one length is 20, and we can actually
retract that data. I mean, we can say
here in our program, we can say also print rectangle one width
and the same way, I can get value for
rectangle one length. Again, for this
object rectangle one, I place this value
in our class here, the self becomes rectangle one. Now I've got rectangle one
width, rectangle one length. I will say escape column W. We will write it to the file and I will run the
program again. Now I extracted those values. These are these attributes. Rectangle one width
is first attribute, and rectangle one length is the second attribute
of my rectangle. I just want to show you
something to make it clear. This self, we called itself, but I can actually call
it anything I want. If I want to call
it Marek, I can do, but then I have to replace
those also with Marek. If I write it to the file
again, escape Column W, if I run the program again, as we can see, it
still works fine. But for the Dunder
in it function, it was agreed that, for the Dunder in it,
we will use self. Simply, if you open the program, you will know immediately
what it is about. I will change it back to
stick to those rules. But anyways, someone
might ask, Mark, but the point of this because it looks like some
unnecessary notation. And as long as we
have only one object, it might actually seem
that way. I agree. However, remember that we can
create the class only once, and then we can create an infinite number of
objects from that class. So now let's create the second object and we
will call it rectangle two. So maybe escape, we will
yank it Yang five Yang. I copied that, I will just
change to rectangle two. I'll change it here,
and then I want to print the values for
Rectangle two this time. Now we created second object. And when Python starts
reading the program, it will see rectangle one first. And then it will
see that we want to create an object from a class
that we call rectangle. So it will find this class. I will replace whatever
we put in parameter here. And as I said, you will
usually see a word self here. It will replace that
self with rectangle one, and it will use that name for
all remaining attributes. So we have rectangle one with is ten and rectangle
one length is 20. Then it will print
all those values. It will see the second object
rectangle two this time. So it will go back
because we can see. I mean, Python will see that we want to create objects
from the same class. So goes back, replace this self with Rectangle
two this time, and all the attributes
will be called rectangle two width and
rectangle two length. And that's what we
want to read here. So if I now write to the
file as cape column W, and we run our program, what we first can see
that the second object for rectangle two has indeed
different place in memory. It's separate object created
somewhere else in memory. I can see only two last
values have changed, but anyway, this
is new location. This is new memory location for object two that
we've just created. But now someone might be
looking at that and say, Mark, this completely
doesn't make sense. Why would I create more objects when they are all
exactly the same? Well, each of these
rectangles has a length of 20 and width of ten. What's the point? Again, indeed, at this moment, that's true. These objects don't have
much meaning because our length and width are
hard coded in our class. We hard coded those values here. However, this doesn't
have to be the case. We can modify our class
now so that it can accept any values for the length and any
values for the width. And to do this, we can add additional parameters to our special Dunder
init function. And when I say
parameters, I mean here, whatever we have
in these brackets, because here is where
we store parameters. Once again, it doesn't
matter what we name them, but to make sense, we will name these parameters
width and length. Or maybe I will add
R rectangle width. I just want to
distinguish it from this, so it's clearer what is what. Then I will add R length, and now I will no longer want
to hard code these values. I just want to read them from whatever program
or user provides. I'll use Rwidth and
guess R length. But what it means now, now
when we build our next object, so I will go here where we
start building our object, I will need three parameters and the first one remains
unchanged and it's self, and it's something I don't
have to provide within brackets because self is
simply the name of my object. We already know that rectangle goes and replaces that self. But I have to provide second and third
parameter for our object. So maybe I say, I want to
have it like ten in width. This will be my width.
And second one, after comma, we separate
them with commas. I say 20. But my second
rectangle will be different. Maybe it will be 5,100.
It will be much bigger. Now let's save it, column W, and now I run the program again. Maybe let's clear it
and run the program. Now what we have
you can see that Python stores these objects still in the same
memory location, but now each object has
different attributes, just to make it more confusing. These what we provide here, ten and 20, for example, these are called arguments. These arguments we
provide here become parameters when they
are read by the class. Okay? So this argument ten becomes parameter
called R width, and then that parameter
R width is used here as a value for
attribute self width. Loads and loads
of names, I know. But the most important is
to understand the concept, not remember all those names. But I just mentioned it just in case you are interested in. Also remember this I keep
referring to as function. But if we write a
function within a class, now we really should
call it method, not function, even though it's function, but I don't know, somebody likes to make it complicated more than it
should be. But never mind. But we've got width
and length, yes. So maybe we could add
additional features for our class and we can
calculate perimeter and arar. Let's go back to our class and we want to define perimeter. And area, and we define them as a separate functions
for our class. So I say define function called perimeter and we read the name of
the object again. So for rectangle one, we will change again
this parameter to rectangle one because
it will have to rewrite that value for
every single object. My second function
will be for area. I will define area as well and also add the self parameter. So let's start writing
this function. We will say print F. We know F strings already
and we say perimeter. Is we have to calculate by
multiplying width and length, which in our case is
self width attribute, multiplied by self length. Attribute. So again, because that might not
be perfectly clear. I create first object
called rectangle one. I created from rectangle class. My first parameter itself is the name of the
object itself. Now I pass first value, which becomes parameter
R width that R width now becomes
rectangle one width. And because this function also replaces that self
with rectangle one, it will read that
rectangle one width and will multiply it by rectangle one length. Hope
that makes sense. And for the area, we print
Area is just realized. They're probably just
watching and saying, like, Mark, what are you doing? Of course, this is area
because that's for the area, and this is perimeter.
Never mind. Be perimeter, how we
calculate perimeter, we do self width. We add self length, and we multiply it by two. But we have to put
brackets here to make sure this operation is done first.
That's better, isn't it? All right, so that
was a little hiccup. But now I can go to my object and maybe let's
remove these lines. We will no longer need them. And now I will say
rectangle one, Area, and I will also
say rectangle perimeter. First thing, somebody might say, where is your print statement? Well, note that the print I used already
within the class. So we don't have to print now. It's already a part of our class O the
method that we wrote, we call that method function, but it's method within class, we call it area and that's
what it does for us. It not only makes
that operation, it also prints the output
of that operation. What I'm really saying
in this line is that I'm interested in object rectangle one,
which is this one, which is created
from class rectangle with these parameters, but I'm only interested
in a function within that class that is called area or method that
is called area, yes. So I will only
display this portion. But in second line, I'm
saying, You know what? I'm also interested
in perimeter. So I will also run this
method within that class. Let's do the same for
rectangle two. All right. Let's write it to the
file, Escape, column W, and let's see what happens
if I run now this program. Okay, it moans something
about line seven. So it's one, two,
three, four, five, six, seven, and of course, it does because I'm stupid. Do you know what it is?
You got a missing bit. It's very important
as you can see. It's the column here and there. And maybe let's
remove this line. Or no, maybe let's add extra one might look
a little bit better. Okay, again, escape, colon
W, let's run it again. Now it's better. It says Area
is 200, perimeter is 60. For first object and
for second object, it says Area 5,000 perimeter
300. And you know what? That's cool, but
the thing is you don't normally do it like that where you write your class and your
objects in the same file. You usually have your class in one file and objects are
created somewhere else, usually as part of your program. So let's see how it can be
done, how it can be split. I'm saying create new
file, Marc object. Mark object, it will
be called dot pi. And now I will copy my
object. To this file. Perfect. Well, I don't need it, in fact, here, so
DN and D. Okay. Now it's removed. I
will write this file. This is my Mark class file, and here is my Mark object. However, I have to add
one more thing because this object has to know
where that class is. So I'm telling it by
using import Mark class. Those files are in
the same folder, so I just have to
specify the name of my file and I can ignore
the dot pi extension. Just provide the name
of the file. That's it. And in this case,
it will be fine. But I just wanted to
mention one more thing. We've got class rectangle, yes, but maybe I want to write
more classes like a circle, like a square,
whatever triangle. But here in my program, I'm only interested
in class rectangle. I'm not interested in class
triangle, for example, right? So I can be more specific here. I'm saying here from Mark class. Import and which class
I want to import. I only want to import rectangle. That's what I'm interested in. So if I had multiple classes, I would only pull
the rectangle one. All right, let's save it now. And now, what I run it's not
Marc class, but Mark object. Let's run it and we can
see it still works fine. I know, it's very long
lesson, and you know what? It's very difficult to
understand. Don't worry about it. Even if you watch entire video and you're still looking at that
and you're like, Mark, what the heck? This is so overcomplicated. I don't know, whatever
you might be thinking. I want to tell you, don't worry. This is really one of the
most difficult subjects in programming generally, not only Python programming, but generally in programming because there is so
many moving parts, so many different names like those attributes,
parameters, blah, blah. It's very easy to get confused with all of
that. And I get you. And you don't even want to know how long it took me
to understand it. And I say I understand it, but sometimes I still
struggle till now. So especially in the
program when you pull multiple classes and the
multiple methods that blah, blah, you know, it's so easy to create that mess that is
difficult to unravel. But never mind, I
hope that anyways, this video is useful and I
hope that does make sense. So thank you for watching.
16. Python IDE - PyCharm vs VSCode: Let's talk about IDE now. IDE stands for integrated
development environment, and the most popular ID for
Python is called Pycharm. But Pycharm is a
Python specific tool. So if you want to work with more than one
programming language, you might want to
use VS code instead, which allows you to install extensions for any programming
language you wish to use. It also has extensions
for bar scripting, answerable, yaml
files, et cetera. VS code is very good and it's something that I use
and I can recommend. Generally, an IDE is simply an application
that helps you write, debug and test your programs. It has some cool features
like auto completion, but I guess many of
you are wondering why we haven't used one
at all in this training. The reason is a little bit
personal, I would say. When I first started
learning Python, every single course or
training began with IDE. You had to go through
several lessons installing and
configuring that ID and it embedded in my
mind that an IDE is necessary to even start
working with Python. Took me quite a while to figure out that it's completely
optional tool. It's something you can use, but it's not a requirement. I mean, you will
probably end up using one ID or another because
it can really help you, especially when your programs become longer and
more complicated. However, I don't want you
to start your journey with that feeling that it's
the first thing you need to know when
learning about Python. Can see, we completed this
entire course without an ID, and it didn't even feel like we are
missing something here. So have a look at
PyCharm and VS code, or maybe you'll find it another
one that you like best. They're all very
easy to install. Think of them as a
notepad on steroids. They will make your
programming more convenient, but I will let you
explore them yourself, as it should be your choice, which one you want to work with. So that's all really about the ID. That's
all I wanted to say. Have a look at them, choose one. It's not that important, really. It's just a convenience tool. So thank you for watching.
17. Further learning: Congratulations on completing this Python programming course. You now possess all the
essential knowledge and skills to start your proper
programming journey. If you are interested in
Dobs and Cloud technologies, then please remember
that you can join our community on automation avenue.com platform where you can learn all about Terraform, AWS, Cloud, Python, and many more Cloud and
DobsRlated topics. I hope that helps and thank
you for watching. Mark.