hello everybody and welcome to the next
part my Python 3 basics series in the
previous video I was showing you guys
how to install set up and begin to use
your Python installation and in this
video what we're going to be talking
about is the print function so the print
function for the most part is kind of
like either it's mostly used just for
debugging at least the way I use it most
of the time I'm using it for debugging
purposes to kind of tell me where I am
in the script and then if you're maybe
editing variables or making changes
along the way you can print out the
changes that are made just so you you
can you know what's like happening under
the hood so it's definitely one of the
most common operations and most common
functions that you use within Python and
it's what's called a built-in function
so you actually you don't actually have
to import anything so there are some
functions that come with your
quote-unquote vanilla installation of
Python but some of them need to be
imported like time or math and all this
kind of stuff but print is used so
frequently that you actually never have
to import the print function at all in
Python 2 7 the print function was a
little bit different it didn't operate
like a function or at least the syntax
wasn't like a function but in 3 3 it's a
lot more like a function so let's go
ahead and get to it so an example of a
print function or any function really is
you call the function name and then in
parentheses you put the functions
parameters well with print the what you
what print does is just outputs to
console whatever you put in there and so
you usually are gonna print a string but
you don't have to print a string but
anyways so let's just say this is an
example of print function okay so we can
save that and typically in my tutorials
I do ctrl s to save and I hit f5 to run
you can also obviously go file save as
or run and run module or file save
really but anyway that's that so when
like stuff starts popping up when I say
ok I'm gonna save and run it and you
didn't see my mouse do anything that's
why anyway so I'm gonna hit f5 it pops
up and you can see that it outputs this
is an example of print function so
pretty basic stuff
really so now let's pop back here and
let's talk about a couple of things real
quick because this is not only gonna be
the print function but also just some
string rules and all that so when you
put something in between quotes it's
known it's known where it's called but
it's known as a string having a very
hard time saying that and you can either
use single quotes or you can use double
quotes now there are advantages and
disadvantages to each but for the most
part you'll see me use single quotes but
if you use single quotes and you try to
do something like this and say let's say
we are going to the store that doesn't
work and if you actually try to run this
you would say it you would see this
invalid syntax there are a couple ways
around this one you could encase
everything in double quotes then the
singular quote within that double quote
will be fine so if we save it this way
we are going to the store no problem
so the next thing that I'll show you
though is if you really insisted on
doing this what if you did this even
though this is a bad example because
it's not really what we want but like
he's like let's say let's say instead
you were saying this is my OCD coming
out anyway hi oh my goodness
anyway save run it and if we pull this
up that worked right you saw how that
worked so it's like a different even
that's so like some people kind of think
like double quotes just are more
powerful so they can encase single
quotes but single quotes can encase
double quotes it really doesn't matter
but let's say you want to use single
quotes but then you also want to say we
are going to the store how would you do
that well you use what's called an
escape character which is the back slash
not to be confused with the forward
slash it's the back slash so typically
it's gonna be right above your Enter key
or your return if you're using like us
our old computer so so you can do that
and what it does is it's called an
escape character because what's gonna do
is it's gonna escape any sort of
functionality of that character and just
leave it as it's hard to say I'd have to
revisit the rules here but at least in
Python in Python 2 on my beginning I'm
confused but you've got like in Python 2
you have in Python 2 you have what's
known as Unicode and you've got like
8-bit whereas in Python 3 you've got
text and just like data right and so
they're like the rules are kind of
different but basically you're just
escaping the functionality here of this
so when we run this you won't see that
nasty little backslash so let's just go
ahead and run it real quick and you'll
see that yeah ok so we're going to the
store and we were able to get away with
it with single quotes so that's just a
couple of quick quick things so you can
do that but another thing that you can
do is what's called concatenation so
what that's going to mean is we're going
to put two strings together so we'll say
hi space there so when you use the plus
sign in concatenation it's gonna put
them directly together so if you did
just hainan space you would see hi there
like jams together so you would out of
space and obviously that's gonna fix it
the other thing the other way that you
can concatenate things is with a comma
and I'll and when you do that with a
comma it's going to add a space so we'll
run it again hi there
now the next thing that you can do is
like I said in originally is you don't
have to have strings you can have a
number in there
or an integer so we'll run that and this
time Python gave us a high-five so you
can see that we're able to do that but
what if what if what if we had a plus
there are we gonna be able to do that
and is it gonna take away our space I
don't know
uh-oh so we actually have a problem it
says that we can't convert an INT object
to a string object because what it's
trying to do is it's taking the string
attempting when you use the plus to add
it to the five so conversely what if we
did five plus hi run that and now we can
see unsupported operand for the integer
because you can't add a string to an
integer so you'll see that I'm getting
all over the place
you'll see that there are actually
different errors that are reported but
it's pretty much for the same reason
you're trying to put two things together
that just don't mesh so there's a couple
of things that you can do obviously you
can use the comma or you can use another
built-in function which would be
something like this so if you wanted to
still you still want to get your high
five you want to add that space but you
really want a plus five there you can
use what's called a string conversion
here and that's another thing that's
built into Python you won't actually
have to import anything to do that you
can save it you can run it and here we
have high five by that same token if
this is say eight and you try to do plus
five it's still a string right string
eight but you can convert that to say an
int save run and now you can see it
actually printed out the mathematical
operation of eight plus five now what if
we did this eight point five plus five
and we run that you can see that it gets
angry at us because the int eight point
five is not an integer so the other
conversion since I'm showing you guys
conversions would be float save that run
that and that is okay everything is
hunky-dory Python is not angry
so that should cover just kind of like
the basics of strings and concatenation
and combining it with integers and
floats and the conversions when you need
to do the conversion and all that so
another time when you might need to use
a conversion like this is if you're
reading from a data file sometimes you
might be reading that stuff in as a
string format same thing if you read
from like a website or something like
that a lot of times it's gonna come in
natively as a string and you'll you'll
need to convert it
out of a string to an int or a float if
it's a number so anyway that should do
four kind of like an introduction to
this kind of stuff and really the print
function since that was the main goal
but really print and strings and
conversions and more on int and actually
mathematical you know actual
mathematical operations because like
stuff like the plus sign is a little bit
has a quite a few uses same thing with
the minus sign so anyways that's going
to conclude this video as always thanks
for watching thanks for all the support
and subscriptions and until next time