Download .PY Sample Files

Jump to:     File Information     Download     How to Open

What is a PY File?

A PY file is a Python source code file: plain text containing a program written in Python, the language created by Guido van Rossum and first released in 1991. Python is one of the most popular programming languages, used for web development, automation, data analysis and machine learning.

You run a PY file with the Python interpreter (python sample.py), and you can open or edit it in any text editor or in an IDE such as VS Code or PyCharm. Python uses indentation to structure code, so editors and tools must keep tabs and spaces intact.

Download PY Sample Files

Below are three short Python 3 programs.

[556 bytes]
[1.4 KiB]
[272 bytes]

PY Sample File Details

SampleWhat it doesLinesFile sizeAsks for input
Sample1.PYChecks whether 29 is a prime number25556 bytesNo
Sample2.PYMenu-driven calculator (add, subtract, multiply, divide)541,398 bytesYes
Sample3.PYPrints the square root of 810272 bytesNo

The files are ASCII text with Windows (CRLF) line endings, which Python accepts on every platform. They use no imports and run on any Python 3 version. Samples 1 and 3 print their result straight away; sample 2 keeps asking for calculations until you answer “no”:

$ python sample-1.py
29 is a prime number

$ python sample-3.py
The square root of 8.000 is 2.828

What You Can Test With These PY Files

  • Code editors: syntax highlighting, indentation and previews.
  • Code runners: online interpreters and sandboxes, including programs that wait for input.
  • Upload filters: accepting or blocking .py files and text/x-python.
  • Line endings: CRLF files in Linux and macOS tools.
  • Static analysis: linters and formatters such as Ruff, Flake8 or Black.

How to Run or Check a PY File

# Run a sample
python sample-1.py

# Check the syntax without running the program
python -m py_compile sample-2.py

# Show the encoding and line endings
file sample-1.py

PY vs Other Script Files

LanguageExtensionRun with
Python.pypython
Shell script.shbash
Ruby.rbruby
Perl.plperl
PHP.phpphp or a web server
Java.javajavac, then java