Home » Python programs

Python | Printing different messages by using different variations of print() method

Python print() method examples: Here, we are going to learn how to print message/text, how to print text with spaces, how to print text in new lines etc in python?
Submitted by Pankaj Singh, on September 28, 2018

In the given example, we are printing the messages by using different forms of the print() method in Python.

Consider the program:

# it will print new line after the messages
print("Hello")
print("World")

# it will print new line
print()

# it will print new line after printing "Hello"
print("Hello",end="\n")
# it willprint new line after printing "World"
print("World")

# it will print new line 
print()

# it will not print new line after printing "Hello"
# it will print space " "
print("Hello",end=" ")
# it will print new line after printing "World"
print("World")

Output

Hello
World

Hello
World

Hello World

Explanation:

print() prints new line after printing the message by default.

end parameter can be used to specify the end character after printing the message - here in this program, we are using end="\n" and end=" ", first one will print a newline after the message and the second one will print the space after printing the message.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.