How To Get Started With Python? | Python Hello World Program

PYTHON FIRST PROGRAM: 

Now we learn about the basic syntax of Python. we run a simple Python program to print a " HELLO WORLD: Create Your First Python Program " on the console.

Python provides us two methods to run a Python program.
1. Using an Interactive interpreter prompt.
2. Using a script file.




How To Get Started With Python? |  Python Hello World Program | Diplomawaale.blogspot.com
Hello World Program


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 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 its impact on the console.

How To Get Started With Python? |  Python Hello World Program | diplomawaale.blogspot.com
Python Hello World


Here, we get the message "Hello World!" printed on the console.

USING A SCRIPT FILE: 


Here, we get the message "Hello World !" printed on the console interpreter prompt is best to run the single-line statements of the code. However, we cannot write the code every time on the terminal. It is not suitable to write multiple lines of code.

Using the script mode, we can write multiple lines of code into a file that can be executed later. For this purpose, we need to open an editor like Notepad, create a file named and save it with the .py extension, which stands for "Python". Now, we will implement the above example using the script mode.

To run this file named first.py, we need to run the following command on the terminal.


How To Get Started With Python? |  Python Hello World Program | diplomawaale.blogspot.com

STEP 1: - Open the Python interactive shell and
click "File" then choose "New", it will open a new blank script in which we can write our code.

How To Get Started With Python? |  Python Hello World Program | diplomawaale.blogspot.com

STEP 2: - Now, write the code and press "Ctrl+S" to save the file.

How To Get Started With Python? |  Python Hello World Program | diplomawaale.blogspot.com

STEP 3: - After saving the code, we can run it by clicking "Run" or "Run Module". It will display the output to the shell.

How To Write Your First Python Applicaion | diplomawaale.blogspot.com

THE OUTPUT WILL BE SHOWN AS:

How To Write Your First Python Applicaion | diplomawaale.blogspot.com


MULTILINE STATEMENT: 


Multi-line statements are written into the notepad like an editor and saved with a .py extension. In the following example, we have defined the execution of the multiple code lines using the Python script.

CODE: 

Writing First Python Program | diplomawaale.blogspot.com
Multiline Statement


SCRIPT FILE: 


Writing First Python Program | diplomawaale.blogspot.com




                                                                                                                                  


Post a Comment

0 Comments