By default python’s print() function ends with a newline. A programmer with C/C++ background may wonder how to print without newline.
Python’s print() function comes with a parameter called ‘end’. By default, the value of this parameter is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter.
In Python, the built-in print()
function is used to display text or output on the screen. The print()
function allows you to specify various parameters to control the output format. One of these parameters is the end
parameter.
By default, the end
parameter in the print()
function is set to '\n'
(a new line character), which means that each call to print()
will end with a newline character, and the next call will start on a new line.
However, you can change the end
parameter to specify a different character or string that will be printed at the end of the output. For example, if you want to print two strings on the same line, you can set the end
parameter to an empty string, like this:
print("Hello", end="") print("World")
This will print "HelloWorld" on the same line, without any space or newline between them.
Alternatively, you can set the end
parameter to a different character or string, like this:
print("Hello", end=";") print("World")
This will print "Hello;World" on the same line, with a semicolon separating the two strings.
In summary, the end
parameter in the print()
function is used to specify what character or string will be printed at the end of the output.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.