Lesson 1
Getting Started
Learn what programming is, what Python is, how Python code works, and how to write your first programs.
What is programming?
Programming is the process of writing instructions that tell a computer what to do.
Computers follow instructions very precisely. They do not automatically know what you mean, so programmers need to give them clear instructions using a programming language.
A program is a set of instructions that a computer can execute.
What is Python?
Python is a programming language used to give instructions to computers.
Python is known for its readable and relatively simple syntax, which makes it a popular language for beginners as well as experienced programmers.
Python is used for many different things, including web development, automation, data analysis, artificial intelligence, and scientific computing.
How Python code works
Python generally runs instructions from top to bottom. The order of your code can change what the program does.
print("First")
print("Second")
print("Third")
The output is:
First
Second
Third
If you change the order of the instructions, the output changes too.
print("Third")
print("First")
print("Second")
The computer follows the instructions in the order you wrote them.
Your first Python program
One of the simplest things you can do in Python is display text on the screen.
print("Hello, world!")
print() is a built-in Python function
that displays something in the program's output.
You can use it to display different messages:
print("Hello!")
print("I am learning Python.")
print("Welcome to PythonPath!")
Strings and text
Text in Python is called a string. Strings are usually written inside quotation marks.
print("Hello")
print("Python")
print("I am learning to code.")
You can use either double quotation marks or single quotation marks for a string.
print("Hello")
print('Hello')
Both examples display the same text.
Be careful: text and numbers are not the same thing.
print("123")
print(123)
In the first example, "123" is text.
In the second example, 123 is a number.
You will learn more about numbers and data types
in the next lesson.
Comments
Comments are notes in your code that Python does not execute.
# This is a comment
print("Hello!")
A comment starts with the # symbol.
You can use comments to explain what part of your
code does.
# Display a welcome message
print("Welcome to PythonPath!")
Basic Python syntax
Syntax means the rules for writing code correctly. Just like human languages have grammar rules, programming languages have syntax rules.
Python is case-sensitive. This means that uppercase and lowercase letters can have different meanings.
print("Hello")
This works because print is written
correctly. Writing Print is different.
Print("Hello")
Python also needs matching parentheses and quotation marks.
print("Hello")
Later, you will learn more syntax rules when we work with conditions, loops, functions, and other Python features.
Common beginner mistakes
Making mistakes is a normal part of programming. Errors help you understand what needs to be fixed.
Missing parentheses:
print"Hello"
Correct version:
print("Hello")
Missing a quotation mark:
print("Hello)
Correct version:
print("Hello")
Incorrect capitalization:
Print("Hello")
Correct version:
print("Hello")
When you see an error, don't panic. Read the error message, look at the line mentioned by Python, and check your code carefully.
Practice
Try these tasks before moving to the mini task.
Task 1:
Write a program that prints Hello!.
Task 2: Print your name, a hobby, and one reason why you want to learn Python.
Task 3:
Create a three-line introduction about yourself
using print().
Mini Task: My Introduction
Create a small Python program that introduces you.
Your program should display at least three lines, such as a greeting, something about yourself, and a goal you have for learning Python.
Try to write the program yourself before looking back at the examples above.