Python Getting Started
Running a Python File
You can use an IDE (Integrated Development Environment) or a Text Editor to write Python code. Here we will use the text editor.
As a developer, you can write Python (.py) files in a text editor and pass those files to the python interpreter for execution.
Let us suppose that we have a Python file named "example.py" that contains the following code:
print("Hello World!")
To execute the above "exmaple.py" file, you need to pass it to the Python interpreter as follows:
$ python example.py
After executing the above command, the output will be as the following:
Hello World!
The Python Command Line
Python also offers a command line to execute code quickly without writing it in a file.
To open the Python command line, run the following command:
$ python3
After executing the above command, it will open the Python command line, and you can write any Python code. The following example will show the "Hello World!" example in the Python command line:
$ python
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World!")
The above code will output the "Hello World!" as follows:
$ python
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World!")
Hello World!
If you want to quit the Python command line, you can simply type the following command:
exit()