In Python, in order to print out text in the console, you can use the print() function. But by default, the print() will add a new line character (based on the OS \n, \r, or \r\n) at the end of the text that it printed out.
If you do not want to print text with a new line character at the end, you can use the end parameter of the print() function.
Example:print("I want to ",end='')
print("continue printing ",end='')
print("on the same line ",end='')
print("using Python print() ",end='')
Output on the same line as expected:
I want to continue printing on the same line using Python print()
More on the "end parameter"
-
The end parameter is used to specify the character or characters that should be printed at the end of the printed text using the print() function.
-
By default end parameter is set to a newline character i.e. \n
-
So when you use the default print() function in python, it always adds a newline character at the end of the text.
-
If you wish to change it to any other character, you can simply use the parameter end= followed by a character.
-
Let's have some fun!
In the below example, we have replaced the end parameter with an emoji and a new line.
print("Hello ",end='😀\n')
print("How are you? ",end='😀\n')
Output:
Hello 😀
How are you? 😀
You can download this article in various formats for your convenience. Choose from the options below:
Facing issues? Have Questions? Post them here! I am happy to answer!
- Python List of Lists with Examples
- Fix: ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter
- How to Convert Python Notebook .ipynb (JSON) to Executable .py Module
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python: Pandas Merge Indicator (Left, Right and Both) Example
- Fix: EOFError Exception in Python
- How to URL Decode a Query String in Python
- How to take user input from the console in a Python program
- Compare two lists in Python and return matches
- How to change the Python Default version
- Fix: KeyError: exception in Python
- How to get the Execution Time of A Python Program
- Fix: ModuleNotFoundError: No module named boto3 [Python]
- How to get unique values from a list in Python
- How to pip install Python Modules in VSCode
- Python: Fix - TypeError: NoneType object is not iterable
- How to delete a file using Python code example
- How to create a dictionary comprehension in Python
- Python: Get just the filename without extension using Path
- How to comment out a block of code in Python
- How to add two float numbers in Python
- Python: How to POST Json Data with HTTP Request
- Get MD5 Hash as Checksum of a String in Python
- Python - Convert float to String
- How to Parse XML String in Python
- Add Bookmark macOS Safari - MacOS
- Convert seconds to minutes using JavaScript - JavaScript
- Error : Invalid key hash.The key hash does not match any stored key hashes - Android
- Fix AWS CLI 2 SignatureDoesNotMatch Error - Signature we calculated does not match - AWS
- 17: Find Factorial of a Number - 1000+ Python Programs - Python-Programs
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes - PHP
- Rust: zsh: no such file or directory: ./main - Rust
- Android: Unknown error code during application install : - Android