Python installation provides a code environment to execute in the following mode
- Interactive mode
- Scripting mode
Python installation provides the following things
- Interpreter
- Python Shell
- Python IDLE Editor
programmer writes a program that contains Python commands or API code, Runs the code with an interpreter, and outputs the result.
Interactive mode can be enabled using Operation System terminal python Shell or IDLE editor.
How to Open Terminal in Python Interactive Mode
- Open terminal,
- In Windows, Open the Run dialog or use Window + R command, type
cmd.exe
or search in the start menu forcommand prompt
- in Mac, Go to
Applications
, NextUtilities
, SelectTerminal
It should be like after opening the command line in Windows
C:\>Users>username>
- Type
python
in the command line, next, press theEnter
key, You should see the following output.
C:\>python
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
in the above last line tells that you are in Python Interactive mode.
If you did not see the above message, then Python is not installed correctly, Please follow python installation
You can run help()
commands
>>> help()
Welcome to Python 3.11's help utility!
If this is your first time using Python, you should check out
the tutorial is on the internet at https://docs.python.org/3.11/tutorial/.
Enter the name of any module, keyword, or topic to get help with writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", and type "modules spam".
help>
Or you can write Python code blocks.
For example, run Hello Word program
>>> print("hello");
hello
>>>
>>> m=5;
>>> n=4;
>>> m+n;
9
Python Scripting mode
Scripting mode enables you to run Python programs.
Programs contain multiple code blocks saved in a file with the extension .py
.
- Create
hello.py
in a text editor - Copy the below code into the file, and save it.
print("hello");
print("welcome");
- Open Terminal
- Run the following command with the file
python hello.py