How to Print with Examples
How to Print with Examples: The print() function in Python is used to display messages on the screen. This function prints strings or objects converted to a string while displaying output.
Syntax:
print(object(s))
How to Print a Simple String in Python
Printing strings is common in Python programming. Here’s how you can print a string using the print() function in Python 3:
Example 1:
print(“Welcome to moji”)
Output:
Welcome to moji
In Python 2, the same example appears as:
print “Welcome to moji”
Printing Multiple Lines in Python
To print multiple strings, such as country names, use separate print() statements:
Example 2:
print(“USA”)
print(“Canada”)
print(“Germany”)
print(“France”)
print(“Japan”)
Output:
USA
Canada
Germany
France
Japan
How to Print Blank Lines in Python
To print blank lines in your program, use the print() function with \n.
Example 3: Print 8 blank lines:
print(8 * “\n”)
OR
print(“\n\n\n\n\n\n\n\n”)
Example Code:
print(“Welcome to moji”)
print(8 * “\n”)
print(“Welcome to moji”)
Output:
Welcome to moji