Table of Contents
Welcome to Python Programming
Python is one of the most popular programming languages in the world, known for its simplicity and readability. In this lesson, we'll get you set up with Python and write your first program.
What is Python?
Python is a high-level, interpreted programming language created by Guido van Rossum in 1991. It's designed to be easy to read and write, making it perfect for beginners.
Installing Python
Visit python.org and download the latest version of Python for your operating system.
Windows Installation:
- Download the Python installer
- Run the installer and check "Add Python to PATH"
- Click "Install Now"
Mac Installation:
- Download the macOS installer
- Run the .pkg file and follow instructions
- Python will be available in Terminal
Your First Python Program
Let's write the traditional "Hello, World!" program:
# This is a comment in Python
print("Hello, World!")
print("Welcome to Python programming!")
# You can also store text in variables
message = "Python is awesome!"
print(message)
Running Python Code
You can run Python code in several ways:
1. Interactive Mode (Python Shell):
python
>>> print("Hello, World!")
Hello, World!
2. Script Mode:
Save your code in a file with .py extension (e.g., hello.py) and run:
python hello.py
Python Syntax Basics
- Python uses indentation to define code blocks
- No semicolons needed at the end of lines
- Comments start with # symbol
- Case-sensitive language
Practice Exercise
Create a Python file and write a program that:
- Prints your name
- Prints your favorite programming language
- Uses variables to store and display information
# Your solution here
name = "Your Name"
favorite_language = "Python"
print("My name is:", name)
print("My favorite programming language is:", favorite_language)