File Formats
  • Audio
  • Video
  • Images
  • 3D & CAD
  • Documents
  • Data
  • Code
  • System
Code
  • Source code
  • Bytecode
  • Programs & libraries
  • Object files
  • Debug info
  • Firmware & ROMs
  • Notebooks
  • Shaders
  • Build files
  • Packages & installers
  1. Home
  2. Code
  3. Source code
  4. PY
.PY
  • Overview

.PY

Python source code

Introduction

A .py file holds a program or module written in Python, as plain text. The Python interpreter runs it directly, compiling it to bytecode on the way and caching that bytecode in a .pyc file.

On Windows, a .pyw file is the same thing, run without opening a console window, which suits programs with their own windows.

Software

  • Python (Windows, macOS, Linux)
  • Visual Studio Code (Windows, macOS, Linux)
  • PyCharm (Windows, macOS, Linux)
  • Jupyter (any browser)
  • Spyder (Windows, macOS, Linux)
  • Thonny (Windows, macOS, Linux)
  • Vim (Windows, macOS, Linux)

Structure

A Python file is plain text with no header. Since Python 3 it is read as UTF-8 unless a comment in the first two lines names another encoding, such as # -*- coding: latin-1 -*-. On Unix systems the first line may be a #! line naming the interpreter, so the file can be run as a command.

Indentation is part of the language: the lines of a block are indented the same amount under the line that opens it, so spaces and tabs matter.

#!/usr/bin/env python3

def greet(name):
    return f"Hello, {name}"

if __name__ == "__main__":
    print(greet("world"))
A small Python script with a #! line and an indented function.
© 2026 fileformats.org About Contact Made by Lewpen