First Python Program
In this section, you will be writing a simple python program for printing a message as the program output. Python provides a function called print which takes a string and prints it to the console.
There are 2 different ways to write a python program.

1. Using Python Interactive shell
Open Command prompt, type python and hit enter. This will launch python interactive shell which shall look as below.

python interactive shell

For printing a message, write print function with “Learning Python!” as its arguments and hit enter. This will print the message on terminal as shown below.

First python program
Congratulations!!! you have just executed your first python program from python shell.

2. Using Python program file
Open your favorite text editor and type

print("Learning Python!")

Save this file as program.py anywhere on your system.
Now open command prompt, navigate to the location where the above file was saved and type command

python program.py
and hit enter.
This will print “Learning Python!” on the terminal.
Congratulations!!! you have just executed your first python script.

Note: Python command will only work if the path of python of python installation is added to search path of your operating system such as path environment variable on Windows or PATH variable in Linux.

3. Using an IDE
Open your favorite IDE and create a new project. On PyCharm, go to File -> New Project, give your project a name and hit Enter. Next right click of the project and select New -> Python File. Write the above print statement in that file.
Finally right click anywhere on the file and Select Run ‘program’. It will execute the program and display the output.

Leave a Reply