How to Import math in Python (and Use It)

How to import math in Python: Command Prompt output of import math, from math import and import math as m

Here’s how to import math in Python: write import math at the top of your file, then call functions with the math. prefix, like math.sqrt(16). The math module ships with Python, so there’s nothing to install: I ran every snippet with Python 3.12.5 and copied the output exactly, including the errors. You’ll see the three … Read more >>

FastAPI Tutorial for Beginners: Build Your First Python API

FastAPI tutorial for beginners: Swagger UI listing the endpoints of an order tracking API

You’ve written some Python and now you want other programs to talk to it over the web. An API does exactly that, and it takes less code than most people expect. Quick answer: this FastAPI tutorial for beginners builds a working order API in one file. Create a FastAPI() app, decorate plain functions with @app.get … Read more >>

Rock Paper Scissors Game in Python (Full Code)

Rock paper scissors game in Python: a best-of-five console game played in Command Prompt

A rock paper scissors game in Python fits in about 30 lines: store which move beats which in a dictionary, let the computer pick with random.choice(), and compare. The whole rule set is one line: I played the game below in a real Command Prompt on Python 3.12.5, typing my moves, including one bad input … Read more >>

How to Install Python on Ubuntu Linux (2026 Guide)

Install Python on Linux Ubuntu: packages.ubuntu.com listing the python3 version for each Ubuntu release

Most Ubuntu Linux systems already include Python 3, so installing Python on Ubuntu often just means adding pip and venv. Open a terminal and run: Which version you get depends on your Ubuntu release. I checked packages.ubuntu.com in October 2026, and the screenshots are real captures of that page and the deadsnakes PPA. This guide … Read more >>

What Does enumerate() Do in Python? (With Examples)

What does enumerate do in Python: Command Prompt output of enumerate over a list of national parks

Wondering what enumerate does in Python? It wraps any iterable and hands you each item together with its position, as an (index, item) pair. So in a for loop you get the counter for free: All the output below is copied from Python 3.12.5 on Windows, and the screenshots show the same runs in Command … Read more >>

How to Run a Python Script (Windows, Mac, Linux, VS Code)

How to run a Python script: Command Prompt running hello.py with python and py

Running a Python script takes one command. Open a terminal in the folder that holds the file and type python followed by the file name. That’s how to run a Python script on Windows; on a Mac or Linux it’s usually python3: My test machine runs Python 3.12.5 on Windows 11, and the Command Prompt … Read more >>

How to Install and Use Multiple Python Versions

Install multiple Python versions: Command Prompt running the same script on Python 3.11, 3.12 and 3.13

You can install multiple Python versions side by side, each in its own folder. On Windows, the Python install manager (py install 3.11) adds versions and py -3.11 picks one. On any system, uv or pyenv install and switch them for you. For the screenshots, this machine has Python 3.12 from python.org plus 3.11 and … Read more >>

How to pip install a Specific Version of a Package in Python

pip install a specific version: Command Prompt showing pip installing tabulate 0.9.0 and Python confirming the installed version

pip installs a specific version when you put == and the version number after the package name. The same command downgrades or upgrades whatever’s already installed: I tested every command below in a real Windows Command Prompt with Python 3.12.5 and pip 24.2, inside a separate environment so you can see each install happen from … Read more >>