Invoking the Interpreter
The Python interpreter is usually installed as/usr/local/bin/python3.15 on Unix systems. You can start it by typing:
Exiting the Interpreter
To exit the interpreter:- Unix/Linux: Press
Ctrl-D - Windows: Press
Ctrl-Zthen Enter - All platforms: Type
quit()
Command Line Editing
The interpreter supports:- Interactive line editing
- History substitution
- Code completion on most systems
Running Python Scripts
You can run Python code in several ways:Execute a File
Execute a Command
Execute a Module
Interactive Mode After Script
Run a script and then enter interactive mode:Argument Passing
When you run a Python script, command-line arguments are available insys.argv:
- No script:
sys.argv[0]is an empty string - With
-c:sys.argv[0]is'-c' - With
-m:sys.argv[0]is the full module name
Interactive Mode
When you start the interpreter without a script, it enters interactive mode:Prompts
- Primary prompt (
>>>): Ready for a new statement - Secondary prompt (
...): Continuation of a multi-line statement
Source Code Encoding
By default, Python source files are treated as UTF-8 encoded. This allows using characters from most languages:Declaring a Different Encoding
To use a different encoding, add a special comment as the first line:With a Shebang Line
If your script starts with a shebang, the encoding goes on the second line:For portable code, stick to UTF-8 encoding and ASCII identifiers even if you can use non-ASCII characters in strings and comments.
