Python print() function with end parameter

Python print() function with end parameter: Here, we are going to learn about the print() function with end parameter which is used to print the message with an ending character.
Submitted by IncludeHelp, on December 26, 2019

print() function

print() function is used to print message on the screen.


# python print() function example

# printing text
print("Hello world!")
print("Hello world!")
print("I\'m fine!")

# printing variable's values
a = 10
b = 10.23
c = "Hello"


# printing text with variable's values
print("Value of a = ", a)
print("Value of b = ", b)
print("Value of c = ", c)


Hello world!Hello world!
I'm fine!
Value of a =  10
Value of b =  10.23
Value of c =  Hello

See the output of the above program, print() function is ending with a newline and the result of the next print() function is printing in the newline (next line).

print() function with end parameter

end is an optional parameter in print() function and its default value is '\n' which means print() ends with a newline. We can specify any character/string as an ending character of the print() function.


# python print() function with end parameter example

# ends with a space
print("Hello friends how are you?", end = ' ')
# ends with hash ('#') character
print("I am fine!", end ='#')
print() # prints new line

# ends with nil (i.e. no end character)
print("ABC", end='')
print("PQR", end='\n') # ends with a new line

# ends with strings
print("This is line 1.", end='[END]\n')
print("This is line 2.", end='[END]\n')
print("This is line 3.", end='[END]\n')


Hello friends how are you? I am fine!#
This is line 1.[END]
This is line 2.[END]
This is line 3.[END]

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

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

© some rights reserved.