First Python Program
In this Section, we will discuss the basic syntax of python by using which, we will run a simple program to print hello world on the console.Python provides us the two ways to run a program:
- Using Interactive interpreter prompt
- Using a script file
Let's discuss each one of them in detail.
Interactive interpreter prompt
Python provides us the feature to execute the python statement one by one at the interactive prompt. It is preferable in the case where we are concerned about the output of each line of our python program.To open the interactive mode, open the terminal (or command prompt) and type python (python3 in case if you have python2 and python3 both installed on your system).
It will open the following prompt where we can execute the python statement and check their impact on the console.
Write the- print("Hello Santosh kumar singh") this command and press enter.
Using a script file
Interpreter prompt is good to run the individual statements of the code. However, we can not write the code every-time on the terminal.We need to write our code into a file which can be executed later. For this purpose, open an editor like notepad, create a file named first.py (python used .py extension) and write the following code in it.
- Print ("Hello Santosh kumar singh"); #here, we have used print() function to print the message on the console.
To run this file named as first.py, we need to run the following command on the terminal.
$ python3 first.py
Get Started with PyCharm
In our first program, we have used gedit on our CentOS as an editor. On Windows, we have an alternative like notepad or notepad++ to edit the code. However, these editors are not used as IDE for python since they are unable to show the syntax related suggestions.JetBrains provides the most popular and a widely used cross-platform IDE PyCharm to run the python programs.