Search This Blog

Wednesday, 15 December 2021

First Program in Python

 

Python Hello, World

free web maker

Python is easy to learn and code and can be execute with python interpreter. We can also use Python interactive shell to test python code immediately. A simple hello world example is given below. Write below code in a file and save with .py extension. Python source file has .pyextension. 

Writing the “Hello, World!” Program

To write the “Hello, World!” program, let’s open up a command-line text editor such as nano and create a new file: hello.py 

Once the text file opens up in the terminal window we’ll type out our program :
print("Hello, World!")

Let’s break down the different components of the code.

1

print() is a function that tells the computer to perform an action. We know it is a function because it uses parentheses. print() tells Python to display or output whatever we put in the parentheses. By default, this will output to the current terminal window.

2

Some functions, like the print() function, are built-in functions included in Python by default. These built-in functions are always available for us to use in programs that we create. We can also define our own functions that we construct ourselves through other elements.

3

Inside the parentheses of the print() function is a sequence of characters — HelloWorld! — that is enclosed in quotation marks. Any characters that are inside of quotation marks are called a string.

4

Once we are done writing our program, save the file and we can exit notepad.

Once you exit out of notpad you’ll return to your shell or cmd.  

Running the “Hello, World!” Program

The hello.py program that you just created will cause your terminal to produce the following output:

Hello, World!

Congratulations! You have written the “Hello, World!” program in Python 3 .
Since the program ran, you can now confirm that Python 3 is properly installed and that the program is syntactically correct.

No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...