To run Python in your terminal, follow these simple steps:
python
or python3
depending on your OS and installation.$ python3
Python 3.11.5 (main, Sep 6 2023, 18:43:08) [Clang 14.0.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, world!")
Hello, world!
To exit the Python shell, type:
>>> exit()
Note: On Windows, use python
. On Mac/Linux, it may be python3
if both Python 2 and 3 are installed.
To run a script saved as a .py
file:
$ python3 script_name.py
Example:
$ python3 hello.py
This will execute the content of hello.py
and print any output to the terminal.
Use the following command:
$ python3 --version
This will display the installed Python version:
Python 3.11.5