Chapter 1 — Getting Started with Python
Welcome to your first coding lesson!
Before we write our first program, let’s talk about some basics.
Programming Languages
A programming language is how humans “talk” to computers.
Just like people have English, Spanish, or Arabic, computers have languages like Python, Java, and C++.
Each language has its own rules, called syntax.
What is Syntax?
Syntax is like grammar in English.
If you don’t follow grammar, a sentence doesn’t make sense.
If you don’t follow syntax, the computer will give you an error.
- Every programming language has different syntax rules.
- In Python, lines are usually written one after another.
- You can write many lines, and the computer will run them in order.
Functions
A function is a small piece of code that does one job.
- You give it a name.
- You can “call” it when you need it.
- Sometimes you give it information (called arguments), and it gives you something back.
Example (don’t worry if this looks confusing yet):
def greet():
print("Hello!")
Here, def starts the definition of a function called greet.
Inside it, we used print — a built-in function in Python.
The print Function
print is one of the most important functions you’ll use in Python.
It tells the computer: “Show this text as output on the screen.”
Example:
print("Hello, world!")
When you run this program, you’ll see:
Hello, world!
More Print Examples
You can print many things:
print("My name is Sarah")
print(2 + 3)
print("The result is:", 2 + 3)
Output:
My name is Joseph
5
The result is: 5
Notice:
- You can write one
printper line. - Python runs them top to bottom.
- You can mix text and math in a single print statement.
Summary
- Programming languages are how we communicate with computers.
- Syntax = the rules of the language.
- A function is a reusable block of code.
printis a built-in function that shows output on the screen.
At the bottom of this page, you’ll find your assignment link.
Try writing your own print statements!