How to run Python code?: In this article, we have provided how to run Python code in various ways such as running Python code through a command line, Linux / Unix and Windows. As we said before Python is an interpreted programming language, developer (or) programmer have to write python files as (.py) extension in the text editor. After that program has to put those files into the python interpreter to be executed.
How to run Python code?
If you want to run Python files, write this in your command line:
C:\Users\Your Name >python helloworld.py
where “helloworld.py” is the name of your python file.
Example: program of “helloworld.py” file
print ("Hello, World!")
Output: Hello, World!
It was so simple to write and run a program in python. First, you have to save your file and then open the command line, use commands to the directory where you have saved your file and run it.
Running Python Code Through Command Line
If you want to run your python program in a command line, just follow these commands as given below:
Syntax of Python: C:\Users\Your Name>python
For the helloworld.py file is your first python program. So, let us write here in a command line. After this, you will be getting the python platform.
>>>print (“Hello, World!”)
which will write hello world in the command line. If you wish that you have done with your output/ command line just follow the command to go back. exit ()
Running Python Code in Different Ways
There are 3 main different ways to start and run the Python code. You can start python from Unix, Dos or any other system which provides you a command line interpreter or shell window. First, enter the python command line. Then follow the commands to start a python.
$python # Unix/Linux
python% # Unix/Linux
C:> python # Windows/DOS
After using any of these commands according to your operating system, you will be running the Python code.
List of Command Line Options present in Python
-sDo not run imported files for looking python paths in startup-vredundant output-XIt disables built-in exceptions (just use strings)-c cmdIf you want to run a python script sent in a cmd stringfileTo run a python script from a given file
-sDo not run imported files for looking python paths in startup-vRedundant output-XIt disables built-in exceptions (just use strings)-c cmdIf you want to run a python script sent in a cmd stringfileTo run a python script from a given file.
|-d||It gives debug output|
|-o||It generates optimized byte code (i.e.resulting in .pyo files)|
|-s||Do not run imported files for looking python paths in startup|
|-X||It disables built-in exceptions (just use strings)|
|-c cmd||If you want to run a python script sent in a cmd string|
|file||To run a python script from a given file|
GUI environment (Graphical User Interface)
As we have said before that using python nowadays almost all the games are developed by this using GUI interface. You can run python on your system if you are having a GUI interface.
- Unix– IDLE is the first Unix IDE for python.
- Windows– In windows Python Win is the first interface and it is an IDE with GUI.
- Mac– Python comes along with IDLE IDE is available from the main website, can be downloadable as either MacBianry or BinHex’d files.
If you are unable to set up your environment, you can take help from your system admin. After setting an environment make sure properly that it is working properly without any errors.
Python has the commenting facility like other programming languages. We can comment by using #