Getting Started with Python FYI

Home Documentation

Getting Started with Python

Welcome to Python FYI! This guide will help you get started with Python programming, from installation to writing your first programs.

What is Python?

Python is a high-level, interpreted programming language known for its simplicity, readability, and versatility. Created by Guido van Rossum and first released in 1991, Python has become one of the world’s most popular programming languages.

Key Features

  • Simple and Readable: Clean, intuitive syntax that’s easy to learn
  • Versatile: Great for web development, data science, AI, automation, and more
  • Large Ecosystem: Extensive standard library and third-party packages
  • Cross-platform: Runs on Windows, macOS, Linux, and more
  • Interpreted: No compilation step needed - run code directly
  • Dynamic Typing: Variables don’t need explicit type declarations

Installation

Download from python.org:

macOS:

# Using Homebrew (recommended)
brew install python

# Or download from python.org

Windows:

  • Download installer from python.org
  • Make sure to check “Add Python to PATH”

Linux:

# Ubuntu/Debian
sudo apt update && sudo apt install python3 python3-pip

# CentOS/RHEL
sudo yum install python3 python3-pip

Option 2: Anaconda (Great for Data Science)

Download from anaconda.com - includes Python, pip, and many scientific packages.

Option 3: pyenv (Version Management)

For managing multiple Python versions:

# macOS
brew install pyenv

# Install latest Python
pyenv install 3.12.0
pyenv global 3.12.0

Verifying Installation

python --version
# or
python3 --version

pip --version
# or  
pip3 --version

Your First Python Program

Hello World

Create a file called hello.py:

print("Hello, Python FYI!")

Run it:

python hello.py

Interactive Python (REPL)

Start the Python interpreter:

python
# or
python3

Try some basic commands:

>>> name = "Python FYI"
>>> print(f"Welcome to {name}!")
Welcome to Python FYI!

>>> numbers = [1, 2, 3, 4, 5]
>>> squares = [x**2 for x in numbers]
>>> print(squares)
[1, 4, 9, 16, 25]

>>> def greet(name):
...     return f"Hello, {name}!"
... 
>>> greet("World")
'Hello, World!'

Basic Concepts

Variables and Data Types

# Numbers
age = 25
price = 19.99
complex_num = 3 + 4j

# Strings
name = "Python FYI"
multiline = """This is a
multiline string"""

# Booleans
is_active = True
is_complete = False

# Lists
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]

# Dictionaries
person = {
    "name": "Alice",
    "age": 30,
    "city": "New York"
}

Functions

# Simple function
def greet(name):
    return f"Hello, {name}!"

# Function with default parameters
def calculate_area(length, width=1):
    return length * width

# Function with multiple return values
def get_name_age():
    return "Alice", 25

name, age = get_name_age()

Control Flow

# If statements
age = 18
if age >= 18:
    print("You're an adult")
elif age >= 13:
    print("You're a teenager")
else:
    print("You're a child")

# For loops
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(f"I like {fruit}")

# While loops
count = 0
while count < 5:
    print(f"Count: {count}")
    count += 1

# List comprehensions
squares = [x**2 for x in range(10)]
even_squares = [x**2 for x in range(10) if x % 2 == 0]

Working with Files

# Reading a file
with open('example.txt', 'r') as file:
    content = file.read()
    print(content)

# Writing to a file
with open('output.txt', 'w') as file:
    file.write("Hello, Python FYI!")

# Reading line by line
with open('example.txt', 'r') as file:
    for line in file:
        print(line.strip())

Package Management with pip

# Install a package
pip install requests

# Install specific version
pip install django==4.2.0

# Install from requirements file
pip install -r requirements.txt

# List installed packages
pip list

# Show package info
pip show requests

Virtual Environments

Create isolated Python environments:

# Create virtual environment
python -m venv myenv

# Activate (macOS/Linux)
source myenv/bin/activate

# Activate (Windows)
myenv\Scripts\activate

# Install packages in virtual environment
pip install requests flask

# Deactivate
deactivate

Next Steps

Now that you have Python set up, explore these areas:

  1. Web Development - Flask, Django, FastAPI
  2. Data Science - NumPy, Pandas, Matplotlib
  3. Machine Learning - scikit-learn, TensorFlow, PyTorch
  4. Automation - Scripts, APIs, web scraping
  5. Best Practices - Code style, testing, packaging

Web Development

  • Flask: Lightweight web framework
  • Django: Full-featured web framework
  • FastAPI: Modern, fast API framework

Data Science & Analytics

  • NumPy: Numerical computing
  • Pandas: Data manipulation and analysis
  • Matplotlib/Seaborn: Data visualization
  • Jupyter: Interactive notebooks

Machine Learning & AI

  • scikit-learn: Machine learning library
  • TensorFlow: Deep learning framework
  • PyTorch: Deep learning framework
  • OpenCV: Computer vision

Automation & Scripting

  • Requests: HTTP library
  • BeautifulSoup: Web scraping
  • Selenium: Browser automation
  • Click: Command-line interfaces

Resources

Ready to dive deeper? Check out our comprehensive documentation for detailed guides and examples across all Python domains!