Welcome to lesson two. And previously, we successfully created
our very first program that printed the words Hello world.
Now, I wanted to use this opportunity to really break this
program down and
help you understand what exactly we did because
I'm going to assume it's your first ever program
and you're new to the world of programming.
So
right here we initiated the command called print. Now, print is a function
with Python. You have inbuilt functions that will do something for you.
Print is one of such functions that will of course print
out whatever it is that we tell it to print.
Now notice that we do have the parentheses,
OK? Opened up. And
typically whenever you're working with functions with Python,
you will have the name of the function.
And then you're gonna have parentheses which are the brackets
and inside of the parentheses,
you're going to have something that we call a variable.
OK?
Variables are kind of like
inputs or data
that we give to the function to work with.
OK. In
this case right now, the
variable is the text. Hello World.
Now we're letting Python know
that Hello world is text. It's a string format.
Don't worry, we're gonna talk a bit more about data types a bit later.
But in order for Python to understand that Hello World is actually a piece of text,
we wrapped it in double quotation marks. As you can see.
That's why Python knows that all
these aren't numbers. This is not some sort of a calculation.
These are just letters or words that need to be printed out.
That's why we wrap them in quotation Mac.
Now, if I was to come over here right now and typed in something,
just something random
notice, it's of course, outside of the quotation marks.
OK.
If I was to go ahead right now and run my program,
you will see right now that it displays an error because
the syntax isn't correct.
If you're going to display anything
using Python and the print function,
it needs to be in quotation mark. So this isn't going to work. Let me go back,
add my
double quotation again,
run
and we're back. OK?
What if I wanted to print? Hello World, let's say five times. OK?
Now I could do this. OK?
I could simply just copy and then come over here, paste, paste, paste, paste.
And then if I was to run,
you can see right now it will print out Hello World five times.
Pretty straightforward.
OK? Let me just go ahead and remove
the four additional lines.
I want to show you a different way.
OK.
We could do something like this. OK?
I am going to create something that I've mentioned before and that's a variable. OK?
Variables. Again, they're like inputs
that we can use to store data.
Now, I'm going to call this variable, let's say text, let's call it text one.
OK?
That's the name of my variable. And I'm gonna say it's equal to
and now in double quotation marks.
Hello
world.
OK.
So what I've done right now is I have simply said,
I'm going to add the text. Hello World to the variable text one.
So text one, the variable text one is now holding it has the value of hello world.
Now check this out. OK?
I'm gonna go over here right now to my print function,
remove
the text, the string
and I'm simply gonna say text
one
because again, text one is equal to hello world.
And now
I'm going to run my command
and here it is we have Hello world.
And of course, I could simply copy this once again
and then I could paste, paste, paste, paste,
run the command
and take a look at that. All of a sudden
we have an issue. Why?
Well, that's because Python
reads
print text one and then again, immediately it sees another print text one,
print text one, print text one
that confuses Python.
So what you want to do right now is we want to add these in separate lines.
It's typically
very good programming syntax, if we're going to run
more than one function,
you want to run them in separate lines,
you should never run multiple functions within the same line.
So
I'm gonna go back in here,
click on run
and there it is, everything is back to normal.
So
that's just a very small snippet of what we're going to be dealing with.
Obviously, we're going to be dealing with far more
advanced functions and programs, but you know,
step by step we're going to get there.
So hopefully
you now understand a bit better what variables are functions
and how the syntax for Python works. Thank you for watching.
I will see you in the next class.