×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

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

By IncludeHelp Last updated : December 08, 2024

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]

Comments and Discussions!

Load comments ↻





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