Python Basics · Lesson 1
Introduction to Python
Start learning Python by understanding what Python is, how Python code works, how print() displays information, and how to predict and write simple Python programs.
What you will learn
- • What Python is and why it is widely used
- • Basic Python syntax
- • How print() works
- • Numbers and strings
- • Basic arithmetic operators
- • How to predict Python output
- • How to identify simple errors
- • How to write your first Python programs
Part 1
What is Python?
Python is a high-level programming language used to give instructions to a computer. Python is known for readable syntax and is used in areas such as web development, automation, data analysis, artificial intelligence and scientific computing.
Example
print("Hello, Python!")CHECK YOUR UNDERSTANDING
What is Python?
Part 2
What is Python mainly used for?
Python can be used for many different types of programming. Beginners often encounter Python in automation, data analysis, web development and artificial intelligence.
CHECK YOUR UNDERSTANDING
Which is a common use of Python?
Part 3
Your first Python command
The print() function displays information as output. Text is normally written inside quotation marks.
print("Hello")
print("Vista Academy")CHECK YOUR UNDERSTANDING
What does print() do?
Predict the output
Think before you run the code
A useful programming skill is predicting what code will do before executing it.
print("Hello")CHECK YOUR UNDERSTANDING
What will print("Hello") display?
print(10)CHECK YOUR UNDERSTANDING
What will print(10) display?
Experiment
Python can calculate
Python can perform arithmetic calculations using operators such as +, -, * and /.
print(10 + 5)print(20 - 8)print(5 * 4)print(20 / 5)CHECK YOUR UNDERSTANDING
What is the output of print(10 + 5)?
CHECK YOUR UNDERSTANDING
What is the output of print(20 - 8)?
CHECK YOUR UNDERSTANDING
What is the output of print(5 * 4)?
CHECK YOUR UNDERSTANDING
What is the output of print(20 / 5)?
Python operators
| Operator | Purpose | Example |
|---|---|---|
| + | Addition | 10 + 5 |
| - | Subtraction | 10 - 5 |
| * | Multiplication | 10 * 5 |
| / | Division | 10 / 5 |
CHECK YOUR UNDERSTANDING
Which symbol performs multiplication in Python?
Important concept
Numbers vs strings
The value 10 and the text "10" look similar, but Python treats them differently. The first is a number. The second is a string.
10Number
"10"String
CHECK YOUR UNDERSTANDING
What is the difference between 10 and "10"?
CHECK YOUR UNDERSTANDING
What will print("10") display?
Joining strings
The + operator can also join strings together.
print("Python" + " Course")CHECK YOUR UNDERSTANDING
What will print("Python" + " Course") display?
Your turn
Complete the code
Fill in the blank: _____("Hello")
Write the function needed to display your name: _____("Your Name")
Debug this code
Programming is not only about writing code. A programmer also needs to identify and fix mistakes.
print("Hello)CHECK YOUR UNDERSTANDING
What is wrong with the code above?
Predict multiple lines of output
print("Python")
print("Data")
print("Analytics")CHECK YOUR UNDERSTANDING
How many lines will this program display?
Coding challenges
Write your first programs
Challenge 1 — Print Vista Academy
Write Python code that displays:
Vista AcademyExpected idea: use print() with a string.
Challenge 2 — Calculate 25 + 15
Write one Python statement that calculates and displays the result of 25 + 15.
print(25 + 15)Mini Challenge
Create your introduction
Write three print() statements that display your name, age and city on separate lines.
print("Your Name")
print(20)
print("Dehradun")Final Challenge
Build your first Python introduction program
Create a small Python program that prints a three-line introduction. Include your name, your city and one thing you want to learn with Python.
Example structure
print("My name is ...")
print("I live in ...")
print("I want to learn ...")Don't copy the example exactly. Replace the values with your own information.
Lesson recap
- ✓ Python is a programming language.
- ✓ print() displays information.
- ✓ Python can perform arithmetic calculations.
- ✓ Operators perform different operations.
- ✓ Numbers and strings are different data types.
- ✓ Predicting output is an important programming skill.
- ✓ Debugging is part of programming.