Python print() function with end parameter (What does end ='' do in Python?)

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. By IncludeHelp Last updated : December 17, 2023

printf() function without end=' ' parameter

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]

Python Tutorial

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.