Python Get Started
January 8th 2020 1344
Welcome back learners to the new topic on the Python lecture series. In this tutorial, we will see how we can run a python program in different ways.
For this tutorial series, I am assuming that you have python3 installed on your computer, If not don't worry I will be using the online Python console or Jupyter notebook so that you can directly start writing python programs using any device.
Verify Python installation on your system
To check if you have python installed on your PC, open the terminal or command prompt(cmd) and type the following command,
If you find that you do not have python installed on your computer, then you can download it for free from the following website: https://www.python.org/
How to write python script and run it on your PC
Let's write the python program step by step and run it.
- Open any text editor
- Copy and paste the below code into your text editor
- Save the file with the name helloworld.py (note that we save the python script with (.py) extension)
- Open the command prompt or terminal and navigate to the directory where you saved your file, and run:
Your output should be
Let's see the live demo here
Python Interactive Shell
Sometimes we need to test a short amount of code in python so the quickest and easiest way to do that without creating a file is using python interactive shell.
To do this on your system type python in our terminal and python shell will prompt.
root@kali:~# python Python 3.6.3 |Anaconda custom (64-bit)| (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
Now here you can write any python code including our hello world program
root@kali:~# python Python 3.6.3 |Anaconda custom (64-bit)| (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello world!") Hello world!
Let's do it in online python shell if you don't have python installed on your system yet, Try writing yourself in the console below
Congratulations, you have written and executed your first Python program.
Here are some pro tips for you so that you never stop learning, There are various online python interpreter use can use to write your code without having python installed on your system,
Google Notebook - It is an online Jupyter Notebook, here you can run python code and as well as install external libraries.
- To setup Python3 Notebook
- Click on File and click on New Python3 Notebook
Repl.it - Online Python3 Interpreter for writing programs