It is a great feature of using Linux kernel base Operating System like Ubuntu, Linux Mint etc that you can easily run or compile Python file through Linux Command Line without installing any IDE for Python Language. Not only Python File, you can interpret Python statement on Terminal.
So this tutorial will let you learn –
- How to create Python File on Terminal.
- How to run Python File on Terminal.
- How to write Python code and run on Terminal.
- Tips to write Python code on Terminal
- Open Terminal by Ctrl + Alt + T
- Open any Text Editor and create a Python file with
file_name.py. If you have Sublime Text Editor then write the following command and hit Enter.
If you don’t have any then write the following command and hit Enter.
By default, Ubuntu has Gedit Text Editor.
- Open Terminal by Ctrl + Alt + T, if it is opened, then no need to reopen.
- First check your current directory of created Python file. To check directory run the following command.
- Then change the directory to your python file
file_name.py. Suppose your current directory of your created file is
/home/you/Desktop, then run the following command.
- After changing directory from Terminal, put the following command.
file_name.py is the name of your Python file. You will see the output of your python file.
- Open Terminal by Ctrl + Alt + T, if it is opened, then no need to re-open.
- Type Python and hit Enter
- Now write Python code and hit Enter to next statement.
- To copy and code on Terminal first select by mouse and Ctrl + Shift + C to copy and Ctrl + Shift + V to paste.
- Since Indention is the most important for Python Programming Language, Put Spacebar twice when Indention is needed. Example:
Fun with Python in Terminal:
- >> Type
8 + 3and hit Enter, you will see result 11
- >> Type
list = [3, 4, 2, 5]and hit Enter. Again Type list and hit Enter, you will see
list = [3, 4, 2, 5]
- >> Go on.