In this tutorial, you will learn-
Python print() function
The print() function in Python is used to print a specified message on the screen. The print command in Python prints strings or objects which are converted to a string while printing on a screen.
Syntax
print(object())
How to Print a simple String in Python?
More often then not you require to Print strings in your coding construct.
Here is how to print statement in Python 3:
Scenario 1:
To print the Welcome to hitechpoints.com, use the Python print the statement as follows
print("Welcome to hitechpoints.com")
Output:
Welcome to hitechpoints.com
Scenario 2:
If you want to print the name of five name, you can write:
print("John")
print("Henry")
print("Azar")
print("Sekar")
print("Raja")
John
Henry
Azar
Sekar
Raja
How to print blank lines
Sometimes you need to print one blank line in your Python program. Following is an example to perform this task using Python print format.
Scenario:
Let us print 9 blank lines. You can type:
print (9 * "\n")
or:
print ("\n\n\n\n\n\n\n\n\n")
Snippet
print("Welcome to hitechpoints.com")
print (9 * "\n")
print("Welcome to hitechpoints.com")
Output
Welcome to hitechpoints.com
Welcome to hitechpoints.com
Print end command
By default, print function in Python ends with a newline. This function comes with a parameter called ‘end.’ The default value of this parameter is ‘\n,’ i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available in only in Python 3+
Scenario 1:
print("Welcome to", end=" ")
print("hitechpoints.com", end="!!")
Output:
Welcome to hitechpoints.com!!
Scenario 2:
Ends the output with ‘!’
print("Python" , end = '!')
Output:
Python!