Python 3 cheatsheet

Python 3: Running Python

6 common Python 3 tasks.

Check the Python version

Print the interpreter version.

python3 --version

Run a script

Run a Python file. On Windows, py or python usually replaces python3.

python3 script.py

Run a one-line command

Run a snippet from the command line.

python3 -c "print(2 ** 10)"

Open the interactive shell

Start the REPL. Exit with exit() or Ctrl+D.

python3

Serve the current folder

Start a simple web server on port 8000.

python3 -m http.server 8000

Caution: For local use only. It is not meant for production.

Pretty-print JSON

Format a JSON file for reading.

python3 -m json.tool data.json

Was this page helpful?