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.

Example

# 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"

print(a)
print(b)
print(c)

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

Output

Hello world!Hello world!
I'm fine!
10
10.23
Hello
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.

Example

# 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')

Output

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

Python Tutorial

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.