Introduction to Python - Your First Program | Python Tutorial (Lesson 1)
Video: Introduction to Python - Your First Program | Python Tutorial (Lesson 1) by Taught by Celeste AI - AI Coding Coach
Watch full page →Introduction to Python - Your First Program
In this lesson, you will learn how to write your first Python program and explore the interactive Python shell, known as the REPL. You'll see how to use the print() function to display messages and how Python can be used as a simple calculator.
Code
# Using the print() function to display text
print("Hello, world!")
# Performing basic math operations in Python
print(2 + 3) # Addition: outputs 5
print(10 - 4) # Subtraction: outputs 6
print(3 * 7) # Multiplication: outputs 21
print(8 / 2) # Division: outputs 4.0 (float)
print(2 ** 3) # Exponentiation: 2 to the power of 3 outputs 8
Key Points
- Python's REPL allows you to quickly test and run code interactively.
- The print() function is used to output text or results to the console.
- Python files use the .py extension and can be run with the command
python3 filename.py. - Python supports basic arithmetic operations like addition, subtraction, multiplication, division, and exponentiation.
- Strings must be enclosed in quotes when using print() to display text.