How to exit Python in the Terminal
There are a couple of different methods that you can use to exit the Python interpreter while in the terminal, which I will go into detail below. The instruction for Linux or macOS is slightly different from Windows, so choose carefully.
Python Interactive Mode
The Python interpreter has an interactive mode that allows you to issue commands to Python. Using this mode, you can write code into the terminal and have immediate feedback from Python. The interactive mode may be the preferred method over using a Python script for some use cases.
The example below demonstrates using Python to print the solutions to some simple math problems.
>>> print(2*3)
6
>>> print(21+5)
26
>>> print(6/3)
2.0
Entering interactive mode for Python is very simple as you type “python
, py
, or python3
into the terminal. However, exiting interactive mode is a little different depending on your operating system.
To confirm that you are in interactive mode, you should see three arrows >>>
.
Below is an example of entering Python interactive mode on Linux.
dev@raspberry:~$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
The post How to exit Python in the Terminal appeared first on Pi My Life Up.