Python print() Function | Python Hello World Program

Python-print-Function-Python-Hello-World-Program
Credit: Canva

Overview – Python print() Function

Let’s get into the Python print() function along with various use cases with grabbing hands-on Python first program Hello World.

What’s Next? – Python print() Function

In this article, I’ll walk you through the Python print() function and some examples of various use cases to implement the print() function in Python. Next, before going to the end, I’ll introduce the Python First program “Hello World!”

Table of Contents

Watch Video Explanation

What is the Python print() function?

Python print() function is a built-in function used to display the messages/output to the Python console or terminal. The function is written with a print keyword followed by Parentheses ().

What is the Python print Syntax?

A syntax in Python is a format – how to write a code, it guides the programmer to write the code systematically.

Here’s the Python print syntax explanation in detail:

				
					print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
				
			

print() function in Python contains 5 parameters. Let’s take a look at how to use them:

*objects = One or more objects/items you want to print. It is referred to as strings, numbers, variables, or any combination of them. You can pass multiple objects separated by commas.

sep = Optional. sep is defined as a separator, which is a string used to separate objects. The default value is a single space (‘ ‘).

end = Optional. end displays the output to the same line just after the last output. The default value is \n meaning it displays output to the new line.

file = Optional. Specifies the file or output where data is written. The default value is sys.stdout.

flush = Optional. It supports Python Boolean values True or False. The default value is False, meaning the output is to be written immediately.

Note: Except the *object parameter none of the above is more important for a beginner level. As we move forward in the Python Tutorial, we will catch up on other Python parameters as well.

For more details: python.org

What are Python print examples?

Here, I’ll discuss some of the Python print() function examples and examine how we can use the Python print function in various cases.

Example 1: (String) – Display your name.

				
					print("My name is Deepak.")

#Output:
My name is Deepak.
				
			

Explanation: The above type of data is considered a String data type in Python. String means anything written inside a single quote () or double (“”) quotes.

OR,

Example 1.1: (Combination of objects) Display your Age.

				
					print("My age is",23)

#Output:
My age is 23
				
			

Explanation: The above example is the combination of objects (String & Number). Here [My age is] is considered a String whereas [23] is an Integer.  Here comma is used as a separator between two objects. 

Note: In the Python String lesson, we will discuss in detail about Python String with examples.

Example 2: (Number) – Display your English subject’s number.

				
					print(75)

#Output:
75
				
			

Explanation: The above type of data is considered an Integer data type in Python. Meaning that when you pass the number, it is considered as an integer in Python.

Note: In the Python Integer lesson, we will discuss in detail about Python Integer data type with examples.

Example 2.1: (Number) – Display the sum of 5 and 10.

				
					print(5+10)

#Output:
15
				
			

Explanation: In the above example, the Python print() function is used to perform as a basic calculator by using the Python (+) Arithmetic Operator.

Note: In the Python Arithmetic Operator lesson, we will discuss in detail with Python Arithmetic Operator examples.

Python Hello World Program

				
					print("Hello World!")

#Output:
Hello World!
				
			

Congratulations!!! Go and celebrate this moment! Just now you have written your first Python program – Hello World!

What’s Your Task?

Write YOUR first Python program — anything you want to display as your first program to welcome and congratulate yourself as a programmer.

You can write your Python program on the YouTube Channel’s video – Python Hello World Program

Conclusion – Python Print() Function

The Python Print() Function is the foundation of the Python function. Here we go with various Python print() examples and get hands dirty on the Python Hello World Program. Whether you’re a beginner writing your first program or an advanced developer debugging complex systems, mastering print() is essential.

Recent Articles