.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
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"))