How to Run Python Program, How to run Python Program on Windows, Linux and other platform
The Interactive Prompt
The Python is simply run on an interactive prompt which is provided by the python interprator for execute a python script. The interactive Prompt look like as >>> and each of code written after this is simply execute after press enter key.
The All operating system provide the facility to run the python programs with command prompts or terminals, The Python software comes with the interpretor name is python and the Linux comes with built in python interpretor and python interpretor also comes in exe for windows platform.
if you want to start interactive prompt just type python and the below screen comes
% python
Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] ...
Type "help", "copyright", "credits" or "license" for more information.
>>>
now you can type your code and press enter then you can see your output
• On Windows, you can type python in a Command Prompt console window. go to Start→Run... dialog box and type cmd and press enter, the command prompt window will appear now type the python and hit enter.
Note- To do this your python path should be set in environment variables.
• On Unix, Linux, and Mac OS X, you might type this command in a shell or terminal window (e.g., in an xterm or console running a shell such as ksh or csh).
• Other systems may use similar or platform-specific devices. On handheld devices, for example, you generally click the Python icon in the home or application window to launch an interactive session. If you have not set your shell’s PATH environment variable to include Python’s install
directory, you may need to replace the word “python” with the full path to the Python executable on your machine. On Unix, Linux, and similar,
Running Code Interactively
When the >>> has come, it’s started, the Python interactive session begins by printing two lines of informational text, then prompts for input with >>> when it’s waiting for you to type a new Python statement or expression. When we are working with interective prompt the results of your code are displayed after the >>> lines after you hit the Enter key.
For instance, here are the results of two Python print statements (print is really a function call in Python 3.0, but not in 2.6, so the parentheses here are required in 3.0 only): % python
>>> print('Hello Python World!')
Hello Python world!
>>> print(3 ** 4)
81
In above example the print function print the message which is passed into it, first print function print a string and second print the power of 3^4.
>>> status = 'okay'
>>> status
'okay'
>>> 3 ** 4
81
>>>
% <== Use Ctrl-D (on Unix) or Ctrl-Z (on Windows) to exit
Here, the fist line saves a value by assigning it to a variable, and the last two lines typed are expressions (status and 3 ** 4)—their results are displayed automatically. The main thing to notice is that the interpreter executes the code entered on each line immediately, when the Enter key is pressed.
The Interactive Prompt
The Python is simply run on an interactive prompt which is provided by the python interprator for execute a python script. The interactive Prompt look like as >>> and each of code written after this is simply execute after press enter key.
The All operating system provide the facility to run the python programs with command prompts or terminals, The Python software comes with the interpretor name is python and the Linux comes with built in python interpretor and python interpretor also comes in exe for windows platform.
if you want to start interactive prompt just type python and the below screen comes
% python
Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] ...
Type "help", "copyright", "credits" or "license" for more information.
>>>
now you can type your code and press enter then you can see your output
• On Windows, you can type python in a Command Prompt console window. go to Start→Run... dialog box and type cmd and press enter, the command prompt window will appear now type the python and hit enter.
Note- To do this your python path should be set in environment variables.
• On Unix, Linux, and Mac OS X, you might type this command in a shell or terminal window (e.g., in an xterm or console running a shell such as ksh or csh).
• Other systems may use similar or platform-specific devices. On handheld devices, for example, you generally click the Python icon in the home or application window to launch an interactive session. If you have not set your shell’s PATH environment variable to include Python’s install
directory, you may need to replace the word “python” with the full path to the Python executable on your machine. On Unix, Linux, and similar,
Running Code Interactively
When the >>> has come, it’s started, the Python interactive session begins by printing two lines of informational text, then prompts for input with >>> when it’s waiting for you to type a new Python statement or expression. When we are working with interective prompt the results of your code are displayed after the >>> lines after you hit the Enter key.
For instance, here are the results of two Python print statements (print is really a function call in Python 3.0, but not in 2.6, so the parentheses here are required in 3.0 only): % python
>>> print('Hello Python World!')
Hello Python world!
>>> print(3 ** 4)
81
In above example the print function print the message which is passed into it, first print function print a string and second print the power of 3^4.
>>> status = 'okay'
>>> status
'okay'
>>> 3 ** 4
81
>>>
% <== Use Ctrl-D (on Unix) or Ctrl-Z (on Windows) to exit
Here, the fist line saves a value by assigning it to a variable, and the last two lines typed are expressions (status and 3 ** 4)—their results are displayed automatically. The main thing to notice is that the interpreter executes the code entered on each line immediately, when the Enter key is pressed.
{ 0 comments... read them below or add one }
Post a Comment