Home >Backend Development >Python Tutorial >How can I suppress newlines and spaces in Python\'s print statements?
Suppressing Newlines and Spaces in Python's Print Statements
In Python, the print function typically appends a newline character to its output. However, this behavior can be modified by adjusting the function's arguments.
One way to suppress the newline is to use the end keyword argument. By setting it to an empty string, you can eliminate the newline after the printed text. For instance:
<code class="python">print('h', end='')</code>
Alternatively, to remove any whitespace separator between multiple print statements within a loop, use the sep keyword argument. By setting it to an empty string, you can eliminate the space between items:
<code class="python">print('a', 'b', 'c', sep='')</code>
These methods allow you to customize the output of the print function, enabling you to control the placement of newlines and spaces, as needed.
The above is the detailed content of How can I suppress newlines and spaces in Python\'s print statements?. For more information, please follow other related articles on the PHP Chinese website!