Python Interpreter
-
Python interpreter helps writing python code in the command line itself.
This is particularly useful to test short snippets of code while doing development or learning basic python.
As the code becomes larger, it becomes difficult to develop using interpreter alone and we may have to create files to keep the code.To open python interpreter, type python or py (for Windows) in command prompt.
Interpreter will become enabled with below message and >>> symbol.
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
We can write python code next to >>>
Code that needs multiple lines are denoted by ...
... automatically comes for multi-line commands like if, for.>>> age = 70 >>> if age < 18: ... print("Young") ... elif age >=18 and age < 60: ... print("Adult") ... else: ... print("Old") ... Old
To exit interpreter, type Ctrl+Z then Enter.