Python # 6 - Execution of Python - OnlineTutorialHub

Search This Blog

Theme images by Storman. Powered by Blogger.

About Fast Edition

Popular Posts

Pages

Services

Blog Archive

Sunday 12 November 2017

Python # 6 - Execution of Python


Execution of Python:-
After Python Installation and Environment Setup , the python interpreter lives in the installed directory.
By default it is /usr/local/bin/pythonX in Linux/Unix and C:\PythonX in Windows, where the 'X' denotes the version number.

There are three different ways to work in Python:
1) Interactive Mode::-
To invoke the Python interpreter in intermediate mode, we need to type “Python” in command line then we can directly enter “Python expressions” and press enter to get the output.

     >>>


“>>>” is the Python prompt. It denotes that Python interpreter is ready for input.
Example : Type 1 + 1 and press enter, We will get 2 as output.
To exit this mode type exit() or quit() and press enter.

OnlineTutorialHub, OTH, Python, Python Execution

2) Script Mode::-
This mode is used to run Python Scripts. And Scripts are nothing but simply written Python program in a file (notepad or notepad++ etc). Extension to save Python Scripts is “.py” i.e. the file having python program should be saved with “.py” then only it turns into Python Script and executable for script mode. We can save these scripts for future use.
For example: helloPython.py
We will write Python code in a separate file using any editor like notepad or notepad++ etc.

OnlineTutorialHub, OTH, Python, Python Execution

Save it by .py extension.

OnlineTutorialHub, OTH, Python, Python Execution

Here helloPython.py is ready to execute in Script Mode.
Now open Command prompt and execute it :
First we need to open command prompt and write directory/path/location where you have save this “.py” file and press enter.

OnlineTutorialHub, OTH, Python, Python Execution

Then write python helloPython.py at the command prompt.

OnlineTutorialHub, OTH, Python, Python Execution


OnlineTutorialHub, OTH, Python, Python Execution

3) Integrated Development Environment (IDE/IDLE):-
IDLE is a graphical user interface (GUI Software) that can be installed along with the Python programming language and is available from the official website .

IDLE provides useful features like code hinting, syntax highlighting and checking, file explorers etc. to the programmer/developer for application development.

By using an IDLE we can get rid of redundant tasks and significantly decrease the time required for application development, using an IDLE can make our life a lot easier.

Any Text Editing Software can be used to write a Python script file. We just need to save the file with the .py extension.

Click on Start button -> All Programs -> Python -> IDLE (Python GUI)

Console/Window opened by IDLE is called Python Shell/Python Prompt.

You can use both “Interactive” as well as “Script mode” in IDLE.

1) Using Interactive mode:
There is no need to save Python Code/Python Script in this mode of IDLE. We can directly write “Python Expressions” on Python Shell/Python Prompt and it will display result simultaneously when you hit enter key.

OnlineTutorialHub, OTH, Python, Python Execution

2) Using Script mode:
i)  Click on Start button -> All Programs -> Python -> IDLE (Python GUI)

ii)  Python Shell will be opened. Now click on File -> New Window.

A new Editor will be opened. Write your Python code here.

OnlineTutorialHub, OTH, Python, Python Execution

Click on file -> save as (sum.py)

OnlineTutorialHub, OTH, Python, Python Execution

Run then code by clicking on Run in the Menu bar.
Run -> Run Module

OnlineTutorialHub, OTH, Python, Python Execution

Result will be displayed on a new Python shell as:

OnlineTutorialHub, OTH, Python, Python Execution


0 on: "Python # 6 - Execution of Python"