π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