Skip to main content

Create a basic Python script

Hi there.
Previously, we discussed the basics of Python.
Now we'll practice writing and running code.
When we work in Python, we refer to what we write as a "script" or a "program." There are subtle differences between the two.
Let's compare a computer program to a theater performance.
Almost every theater performance includes a written script.
Actors study and memorize a script to say it out loud to an audience.
However, that's not the only component.
There's also the whole performance.
Directors make decisions on what lighting to use, or costumes, or what the stage looks like.
The performance as a whole involves a lot of design choices, like set design, lighting, and costumes.
The process of creating this production is similar to the process of programming in Python.
Programming involves a lot of design decisions.
But the process of scripting in Python is more like writing the specific words that the actors will say.
In Python, it's good practice to start with a comment.
A comment is a note programmers make about the intention behind their code.
Let's add one now.
We start with the hash symbol to indicate that this is a comment.
And then we'll add details about our intention.
Here we're going to print "Hello Python" to the screen.
Okay, now let's write our first line of Python code.
This code uses print.
Print outputs a specified object to the screen.
After print, we put what we want to output in parentheses.
In this case, we want to output the string "Hello Python!" We must place string data in quotation marks.
These quotation marks are just one example of syntax that you will encounter in Python.
Syntax refers to the rules that determine what is correctly structured in a computing language.
And now, we'll run this code so the computer can output the string.
You just ran your first line of code.
Since our syntax is correct, the string is now displayed.
Now that you've experience writing and running code in Python, we're ready to discuss its basic components.
Meet you soon.