>> So, Christopher has shown you how to get
Visual Studio Code working with the Python extension,
now let's go into Visual Studio Code and
actually start trying out some of our code.
Now, when you work inside Visual Studio Code,
you're going to need to create a folder on your file system first,
and that's a place where you can keep
all your files together that you're working on.
So I've already gone ahead and I've created a folder.
So as soon as I open up Visual Studio Code,
I'm going to want to go to "File," "Open
folder," and open up that folder that I've precreated.
So I've already created
a folder called Intro to Python development,
I'm going to open that folder now,
and now that gives me a place to
store all the files I'm going to be working on.
Once I've got that folder open and I can see
the folder name listed over here on the left,
then I can say "New file" to
create a new Python file inside that folder.
So now, I can try out that print statement.
So we say, ''Print, Hello world."
Now, initially, there's no way that
Visual Studio Code can tell that
what I've written is a Python module.
So it's when I save the file
that I tell Visual Studio it's Python.
So I'll just save it by going to ''File,"
"Save," or Control S if you like keyboard shortcuts,
and once it's saved,
I'm going to make sure I call it Helloworld.py,
and that PY extension is a cue
to Visual Studio Code that I've just created a Python script.
You'll see right away some colors appearing.
That's a good sign because it's actually using code
highlighting to indicate that
the hello world is the string by showing up in red and so on.
So I can tell now that
Visual Studio Code recognizes this as a Python script.
Then I want to run that.
So to run that code,
and this will be your ultimate test of whether
you got all your Python installed correctly,
you just type "Python" and then the name of your script,
and I called mine Helloworld.py.
If you forget your file name,
don't worry, it's at the top of the tab,
and then you hit "Return" and sure enough,
there's Hello world displayed on the screen.
So I've successfully run my first script in Python.
As I mentioned, you can put
single quotes or double quotes around your string.
I'm just going to use Control S to save that file again,
go back to "Command line," I'm going to use
the up arrow which allows me to go to the previously run command,
and rerun my script,
but this time with double quotes around the string,
and sure enough, still displays Hello world.
So as I mentioned, single quotes,
double quotes, either one will work just fine.
Now what if I want someone to input a value?
Well, I could create a variable called Name,
and say "Input, what is your name?"
Then I can say hello,
and then maybe after I say hello,
I say let's print the name on the screen.
So let's say hello to the person who has typed in their name.
So now, save that.
Go to my code, rerun that,
and it says, "What is my name?"
My name is Susan, and now I
see "Hello Susan" appearing in the output.
So the input command I said is
a way for me to ask for input from a user,
and then I can take that input and
store it back inside a variable.
Once you start having multiple lines
of output displaying on the screen,
you may want those blank lines.
So at anytime you can do something like "Print,
hello," and then I can just say "Print,
world," and you will notice those appear on different lines,
so you can see hello world appear in different lines.
I'm going to show you another useful little command
in Visual Studio Code here,
we're starting to get to the bottom of the command line output.
So it just typing the word "CLS," we'll clear
the screen and take us back to the top of this output here.
Useful little thing when you've got
a lot of outputs displaying on the screen.
Another way of putting
output over multiple lines is you can use that
slash n. Slash n is an escape character that means,
please insert a new line.
So that will also display a line of code over two lines of output.
So slash n is a way of saying new line, right inside a string.
This is really handy when used when
displaying output to use on a console application,
but as I mentioned, print is also very
popular for coders trying to debug their code.
So if I was writing some code that was doing some math,
x equals 532 plus 12,
and then I say y equals x divided by 0,
now I know that dividing by 0 is going to cause an error,
and then I say "Print,
yay I did math."
So I write a very simple little program here,
and I save it, and I go down,
and I run that program,
and it blows up.
Now, I'm using a very simplified example.
You can probably look at my code
and guess which line of code blowed up.
It's the divide by 0.
But what if this was inside a 500,
600 line program with multiple modules and functions,
sometimes it'd be trough to track
down where that line is blowing up,
even though in the error message it
does give you a line number which gives you a hint.
So sometimes when I'm trying to debug my code,
I will literally write things like
saying ''Adding numbers,'' sorry,
promised I would use single quotes here,
'Adding numbers', and then I add my numbers,
and then I'll say print,
'dividing numbers,' and then I will divide the numbers,
and then I have my print statement saying,
'Yey I did math.'
That way, when I go and I run my code,
you can see that the adding numbers message appeared,
the dividing numbers message appeared,
and then I got an error message.
So it can help me flow back
through my code to figure out what code executed successfully,
and whichever print statement I didn't see is
probably the one right after the line that failed.
So don't be afraid to use print statements as a debugging tool,
as you're learning to code.