Python Programming
Introduction to Python
Introduction to Python
Section titled “Introduction to Python”Python is a high-level, interpreted programming language known for its clean syntax and readability. Created by Guido van Rossum and first released in 1991, Python has become one of the most popular programming languages in the world.
Why Learn Python?
Section titled “Why Learn Python?”- Beginner-Friendly: Python’s clear syntax makes it perfect for newcomers
- Versatile: Used in web development, data science, AI, automation, and more
- Large Ecosystem: Thousands of libraries and frameworks available
- High Demand: One of the most sought-after skills in the job market
- Great Community: Extensive documentation and helpful community
What You’ll Learn
Section titled “What You’ll Learn”In this Python tutorial series, we’ll cover:
- Python Basics - Variables, data types, operators
- Control Flow - Conditionals, loops, logic
- Functions - Writing reusable code
- Object-Oriented Programming - Classes and objects
- Modules & Packages - Organizing your code
- File Handling - Working with files
- Exception Handling - Error management
- Advanced Topics - Decorators, generators, and more
Setting Up Python
Section titled “Setting Up Python”Installing Python
Section titled “Installing Python”Windows
Section titled “Windows”- Download Python from python.org
- Run the installer
- Important: Check “Add Python to PATH” during installation
- Verify installation: Open Command Prompt and type
python --version
# Using Homebrew (recommended)brew install python
# Verify installationpython3 --version# Ubuntu/Debiansudo apt updatesudo apt install python3 python3-pip
# Verify installationpython3 --versionYour First Python Program
Section titled “Your First Python Program”Let’s write the classic “Hello, World!” program:
# This is your first Python program!print("Hello, World!")Running the program:
- Save the code in a file called
hello.py - Open terminal/command prompt
- Navigate to the file location
- Run:
python hello.py(orpython3 hello.pyon macOS/Linux)
You should see:
Hello, World!Congratulations! You’ve written your first Python program!
Python Interactive Mode
Section titled “Python Interactive Mode”Python also has an interactive mode (REPL) that’s great for experimenting:
$ pythonPython 3.12.0 (main, Oct 2 2023, 00:00:00)>>> print("Hello from interactive mode!")Hello from interactive mode!>>> 2 + 24>>> exit()Next Steps
Section titled “Next Steps”Now that you have Python set up, you’re ready to dive into the basics! In the next lesson, we’ll explore:
- Variables and data types
- Basic operators
- Input and output
Quick Reference
Section titled “Quick Reference”| Concept | Example |
|---|---|
| Print output | print("Hello") |
| Comments | # This is a comment |
| Multi-line comments | """Triple quotes""" |
| Run a script | python script.py |
| Interactive mode | python |