CPython is the reference implementation of the Python programming language. Written in C and Python, CPython provides the complete Python runtime environment including the interpreter, standard library, and development tools. This version (3.13.2) includes the latest features, performance improvements, and bug fixes for the Python 3.13 series.
Python provides built-in functions and types that are available without import:
# Built-in functions are available directly
print("Hello, World!")
len([1, 2, 3])
type(42)Standard library modules require imports:
import os
import sys
import re
import json
from collections import defaultdict, Counter
from pathlib import Path# Using built-in functions and types
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
maximum = max(numbers)
print(f"Total: {total}, Max: {maximum}")
# Using standard library modules
import os
import json
from datetime import datetime
# File operations
current_dir = os.getcwd()
files = os.listdir(current_dir)
# JSON handling
data = {"name": "Python", "version": "3.13.2"}
json_string = json.dumps(data)
# Date/time operations
now = datetime.now()
formatted = now.strftime("%Y-%m-%d %H:%M:%S")
# List comprehensions and iteration
squares = [x**2 for x in range(10)]
even_squares = [x for x in squares if x % 2 == 0]Python's architecture consists of several key components:
This design provides a complete programming environment that balances ease of use with powerful capabilities, making Python suitable for everything from scripting to large-scale applications.
Core Python functionality available without imports, including 149 built-ins (functions, types, and constants), fundamental data types (int, str, list, dict), and the complete exception hierarchy.
# Data conversion functions
int(value) -> int
str(value) -> str
float(value) -> float
bool(value) -> bool
# Container functions
list(iterable) -> list
dict(mapping) -> dict
set(iterable) -> set
tuple(iterable) -> tuple
# Iteration functions
len(obj) -> int
max(iterable) -> object
min(iterable) -> object
sum(iterable) -> numberThe most commonly used standard library modules that form the foundation of Python development, including system interface, text processing, data structures, and file operations.
# System interface
import os
import sys
import platform
# Text processing
import re
import string
# Data structures
import collections
import itertools
import functoolsModules for handling various data formats, serialization, compression, and data manipulation tasks commonly needed in Python applications.
# Data formats
import json
import csv
import pickle
import tomllib
# Compression
import gzip
import zipfile
# Data types
import datetime
import decimal
import graphlibComprehensive networking capabilities including HTTP clients/servers, URL handling, email processing, and low-level socket programming.
# HTTP and URLs
import urllib.request
import urllib.parse
import http.client
# Network protocols
import socket
import ssl
import emailSupport for concurrent and parallel programming including threading, multiprocessing, asynchronous programming, and subprocess management.
# Threading
import threading
import queue
# Async programming
import asyncio
import contextvars
# Process management
import subprocess
import multiprocessingTools for software development including logging, debugging, testing, command-line argument parsing, and code introspection.
# Development tools
import logging
import argparse
import unittest
# Debugging
import pdb
import tracebackOperating system interface, file system operations, process management, and platform-specific functionality.
# OS interface
import os
import os.path
import pathlib
import shutil
# System information
import platform
import sysCryptographic functions, secure random number generation, and security-related utilities for building secure applications.
# Cryptography
import hashlib
import hmac
import secrets
# Security
import ssl
import getpass# Conditional execution
if condition:
pass
elif other_condition:
pass
else:
pass
# Loops
for item in iterable:
pass
while condition:
pass
# Exception handling
try:
risky_operation()
except SpecificError as e:
handle_error(e)
finally:
cleanup()
# Context management
with open('file.txt') as f:
content = f.read()# Function definition
def function_name(param1: type, param2: type = default) -> return_type:
"""Function docstring."""
return result
# Class definition
class ClassName:
def __init__(self, param):
self.attribute = param
def method(self):
return self.attribute
# Decorators
@decorator
def decorated_function():
pass# List comprehension
result = [expression for item in iterable if condition]
# Dictionary comprehension
result = {key_expr: value_expr for item in iterable}
# Set comprehension
result = {expression for item in iterable}
# Generator expression
result = (expression for item in iterable)from typing import List, Dict, Optional, Union, Callable, TypeVar, Generic
# Type annotations
def process_items(items: List[str]) -> Dict[str, int]:
return {item: len(item) for item in items}
# Optional and Union types
def get_value(key: str) -> Optional[str]:
return data.get(key)
# Generic types
T = TypeVar('T')
class Container(Generic[T]):
def __init__(self, value: T) -> None:
self.value = value# Numeric types
class int:
def __init__(self, value=0) -> None: ...
def __add__(self, other) -> int: ...
def __str__(self) -> str: ...
class float:
def __init__(self, value=0.0) -> None: ...
def __add__(self, other) -> float: ...
class bool(int):
def __init__(self, value=False) -> None: ...
class complex:
def __init__(self, real=0, imag=0) -> None: ...
@property
def real(self) -> float: ...
@property
def imag(self) -> float: ...
# Sequence types
class str:
def __init__(self, value='') -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, index) -> str: ...
def upper(self) -> str: ...
def lower(self) -> str: ...
def split(self, sep=None) -> list: ...
def join(self, iterable) -> str: ...
class list:
def __init__(self, iterable=None) -> None: ...
def append(self, item) -> None: ...
def extend(self, iterable) -> None: ...
def insert(self, index, item) -> None: ...
def remove(self, item) -> None: ...
def pop(self, index=-1) -> object: ...
def sort(self, key=None, reverse=False) -> None: ...
class tuple:
def __init__(self, iterable=None) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, index) -> object: ...
def count(self, item) -> int: ...
def index(self, item) -> int: ...
# Mapping types
class dict:
def __init__(self, mapping=None, **kwargs) -> None: ...
def __getitem__(self, key) -> object: ...
def __setitem__(self, key, value) -> None: ...
def get(self, key, default=None) -> object: ...
def keys(self) -> dict_keys: ...
def values(self) -> dict_values: ...
def items(self) -> dict_items: ...
def update(self, other) -> None: ...
# Set types
class set:
def __init__(self, iterable=None) -> None: ...
def add(self, item) -> None: ...
def remove(self, item) -> None: ...
def discard(self, item) -> None: ...
def union(self, other) -> set: ...
def intersection(self, other) -> set: ...class BaseException:
def __init__(self, *args) -> None: ...
def __str__(self) -> str: ...
@property
def args(self) -> tuple: ...
class Exception(BaseException):
pass
class ValueError(Exception):
pass
class TypeError(Exception):
pass
class KeyError(LookupError):
pass
class IndexError(LookupError):
pass
class FileNotFoundError(OSError):
pass