Running Python

Python Interpreter

There are a couple of ways to execute Python code. One way is through the Python Interpreter, which allows for on the fly code testing and sandboxing. The Python Interpreter uses REPL:

  • Read: the user input
    • Some constructs like loops might be multiple lines
  • Evaluate: the input
    • Attempt to perform the instruction
  • Print: to the screen and
    • Print any requested info or an error with stack trace
  • Loop:
    • Print the next prompt

The Python Interpreter can be launched from the command prompt or terminal using the following commands:

Linux & OS X

python2 or python opens up Python 2

python3 opens up Python 3

Windows

python -2 opens up Python 2

python -3 opens up Python 3

Additional Commands/Info

exit() or shortcut crtl-D to exit the Python Interpreter.

Typing simply a variable or expression will yield a printed output

Python Source Files

The other way to run Python code is using source files with the extension of .py. Python does not require compilation on the user's end. Executing .py source code is similar to starting the Interpreter.

Be sure to:

  • Use appropiate bash commands for the source code's Python version
  • Include filename and extension after bash command
  • Include any arguments after filename and extension.

results matching ""

    No results matching ""