Module 0-1: Python File Structure, Syntax, and Printing
In this lesson, we will cover the absolute bare basics on how to make a simple program in Python.
File Structure
How do you actually write a Python program? In other languages, like Java, for example, you require what is often called boilerplate code, which is a term used to refer to code that is required for a program to run, but is otherwise unrelated to how a program functions (for instance, a main function). Python is a language written first and foremost with simplicity in mind. In Python, there is no boilerplate code required. We can make a blank Python file and immediately start writing code.
Printing
Printing in Python is probably the simplest operation that you can do, that you are able to actually see. Printing is essential for you to use when debugging your project, and for displaying changes to data that occurs over a program's lifecycle.
A print statement is written as such:
If you run your code, in the console you will see:
You can see that the print statement in Python makes the console display whatever data you give it. And there you go; that's your first program in Python!
Syntax
Syntax is a very important concept in programming languages. Syntax is the "grammar" of a programming language. If your code doesn't follow syntax rules, then your computer won't run it. If you told someone to do something for you in your native language, but you mispronounced a few words, then they aren't going to understand until you clarify for them. Likewise, a computer won't run a program with syntax until you fix it. IDEs are useful, as they will usually highlight syntax errors for you with a squiggly red underline.
A print statement is a function in Python. What specifically functions are will be covered at a later time, but functions have to follow a specific syntax. You must type in the function's name, and then a pair of parentheses afterward. In our case, we typed in
print()Functions will perform different behaviors depending on the parameters you pass in. In our case, we passed in
``Hello World!````Hello World!``