Introduction to Python

What Python is, why it dominates data science and AI, and how it compares to other languages.

Beginner 8 min read 5 examples

What is Python?

Python is a high-level, interpreted programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability and simplicity - its design philosophy is that there should be one obvious way to do things, and that code should be readable without needing extensive comments.

Python is dynamically typed (you do not declare variable types), garbage collected (memory is managed automatically), and supports multiple programming paradigms: procedural, object-oriented, and functional.

Python
# Python is readable - this is nearly plain English
name = "Alice"
age  = 30

if age >= 18:
    print(f"{name} is an adult.")
else:
    print(f"{name} is a minor.")

# No semicolons, no braces, no type declarations
# Indentation defines code blocks

Why Python is Popular

Python has been the most popular programming language in the TIOBE Index and Stack Overflow surveys for several years. Several factors drive this:

  • Readable syntax - code is close to pseudocode, lowering the barrier to entry
  • Huge standard library - "batteries included" means most common tasks have a built-in solution
  • Massive ecosystem - PyPI hosts over 500,000 packages covering every domain
  • Dominance in AI/ML - PyTorch, TensorFlow, scikit-learn, pandas, and NumPy are all Python-first
  • Versatility - the same language works for quick scripts, web APIs, data pipelines, and research
  • Community - large, welcoming community with extensive documentation and tutorials

Key Use Cases

DomainWhat Python doesKey libraries
Data ScienceData analysis, visualization, statisticspandas, NumPy, matplotlib, seaborn
Machine LearningTraining models, inference, researchscikit-learn, PyTorch, TensorFlow, XGBoost
AI ApplicationsLLM apps, RAG, agents, embeddingsLangChain, LlamaIndex, openai, anthropic
Web DevelopmentREST APIs, full-stack web appsFastAPI, Django, Flask
AutomationScripts, file processing, web scrapingrequests, BeautifulSoup, Playwright, Selenium
DevOpsInfrastructure as code, CI/CD toolsAnsible, AWS CDK, Fabric
FinanceQuantitative analysis, algorithmic tradingzipline, backtrader, yfinance

Python 3 vs Python 2

Python 2 reached end-of-life on January 1, 2020. All new code should use Python 3. The current stable series is Python 3.12 (as of 2024), with 3.13 in active development.

FeaturePython 2Python 3
printprint "hello" (statement)print("hello") (function)
String defaultbytes (ASCII)Unicode (str)
Integer division5/2 = 25/2 = 2.5
f-stringsNot availableAvailable from 3.6+
async/awaitNot availableAvailable from 3.5+
Type hintsNot availableAvailable from 3.5+
SupportEOL since 2020Active - use this

How Python Works

Python is an interpreted language. When you run a .py file, CPython (the reference implementation) compiles it to bytecode (.pyc files), then the Python Virtual Machine executes that bytecode. This happens transparently - you never manually compile Python code.

Shell
# Write your code in a .py file
$ python hello.py        # CPython compiles + runs it
$ python3 hello.py       # On systems with both Python 2 and 3

# Or use the interactive REPL (Read-Eval-Print Loop)
$ python3
>>> 2 + 2
4
>>> print("Hello")
Hello
>>> exit()
CPython vs other implementations

CPython is the standard. Other implementations include PyPy (JIT-compiled, much faster for CPU-bound code), Jython (runs on JVM), and MicroPython (for microcontrollers). When people say "Python" they almost always mean CPython.

Python vs Other Languages

Languagevs PythonWhen to prefer the other
JavaScriptPython is cleaner for scripting; JS required for browsersFrontend web, Node.js server, React/Vue apps
Java/C#Python is faster to write; Java/C# have stronger static typingEnterprise systems, Android (Java), game dev (C#)
Go/RustPython is slower at runtime; Go/Rust are compiled and much fasterHigh-performance systems, CLI tools, microservices
RPython has broader ecosystem; R has better built-in statsStatistical research, academia, specific bioinformatics
SQLDifferent tools - Python calls databases, SQL queries themData queries belong in SQL; use both together

First Look at Python Code

Python
# Variables - no type declarations needed
name    = "Alice"
age     = 30
height  = 1.75
is_admin = True

# Lists (like arrays)
fruits = ["apple", "banana", "cherry"]
print(fruits[0])   # apple
print(fruits[-1])  # cherry (negative index)

# Dictionaries (key-value pairs)
user = {"name": "Alice", "age": 30}
print(user["name"])  # Alice

# Functions
def greet(person):
    return f"Hello, {person}!"

print(greet("Bob"))  # Hello, Bob!

# Classes
class Dog:
    def __init__(self, name):
        self.name = name

    def bark(self):
        return f"{self.name} says woof!"

dog = Dog("Rex")
print(dog.bark())  # Rex says woof!
Output
apple
cherry
Alice
Hello, Bob!
Rex says woof!
Follow along in the REPL

The fastest way to learn Python is to type examples directly into the Python REPL. Open a terminal and run python3. You can test any expression instantly without creating a file. Use it as a calculator, an experiment pad, and a quick reference throughout this tutorial.

Frequently Asked Questions

Yes - Python is widely regarded as the most beginner-friendly programming language. Its syntax reads almost like English, it uses indentation instead of braces so code structure is visual, there is no need to declare variable types, and a working program can be written in a single line. Most universities use Python as a first language for exactly these reasons.

Python is used across many domains: Data science and ML (pandas, NumPy, scikit-learn, PyTorch, TensorFlow), Web development (Django, FastAPI, Flask), Automation and scripting (file processing, API calls, browser automation with Playwright), DevOps (Ansible, AWS CDK), and AI applications (LangChain, LlamaIndex). It is the dominant language for AI/ML research.

Python 3 - always. Python 2 reached end-of-life on January 1, 2020 and receives no security updates. All major libraries dropped Python 2 support years ago. If you encounter Python 2 code at work, the goal should be migrating it to Python 3, not writing new code in Python 2.

Basic syntax and core data structures: 2-4 weeks with daily practice. Comfortable writing useful scripts and programs: 2-3 months. Proficient enough for professional work (depending on your domain): 6-12 months. Python is quick to start but has significant depth - libraries like NumPy, Django, or asyncio each have their own learning curve on top of the core language.