How to Print without newline in Python?
Last Updated :
26 Apr, 2025
In Python, the print() function adds a newline by default after each output. To print without a newline, you can use the end parameter in the print() function and set it to an empty string or a space, depending on your needs. This allows you to print on the same line. Example:
Python
print("geeks", end =" ")
print("geeksforgeeks")
Outputgeeks geeksforgeeks
Explanation: In the first print() statement, end=" " is used, which means a space (" ") is printed instead of the default newline after the word "geeks". The second print() statement prints "geeksforgeeks" immediately after "geeks", on the same line.
Using Python join
You can use the join() method to combine elements of an iterable into a single string and then print it.
python
a = ["Hello", "World"]
print(" ".join(a))
Explanation: " ".join(a) Joins the elements of the list a using a space as the separator, resulting in the string "Hello World".
Using asterisk ( * ) operator
In Python, you can use the asterisk (*) operator to unpack a list or tuple and print its elements without adding a newline between them.
Python
a = [1, 2, 3, 4, 5, 6]
print(*a)
Explanation: The * operator unpacks the list, passing its individual elements as separate arguments to the print() function. This prints the list elements separated by spaces.
Using Python sys Module
To use the sys module, first, import the module sys using the import keyword. Then, make use of the stdout.write() method available inside the sys module, to print your strings. It only works with string If you pass a number or a list, you will get a TypeError.
Python
import sys
sys.stdout.write("GeeksforGeeks ")
sys.stdout.write("is best website for coding!")
OutputGeeksforGeeks is best website for coding!
Explanation: Unlike the print() function, which automatically adds a newline at the end of the output, sys.stdout.write() writes the specified text to the console exactly as it is, without any extra characters (like a newline).
Related Articles:
Similar Reads
How to Print a List Without Brackets in Python In this article, we will see how we can print a list without brackets in Python. Whether we're formatting data for user interfaces, generating reports, or simply aiming for cleaner console output, there are several effective methods to print lists without brackets.Using * Operator for Unpacking List
2 min read
How to Print a Tab in Python In Python, printing a tab space is useful when we need to format text, making it more readable or aligned. For example, when displaying data in columns, we might want to add a tab space between the values for a cleaner appearance. We can do this using simple methods like \t, the print() function or
2 min read
Ways to Print List without Quotes - Python The task of printing a list without quotes in Python involves displaying the elements of the list without the default string representation which includes quotes around string elements. For example, given the list a = ['a', 'b', 'c', 'd'], the goal is to print the list in the format [a, b, c, d] wit
2 min read
Print new line in Python In this article, we will explore various methods to print new lines in the code. Python provides us with a set of characters that performs a specific operation in the code. One such character is the new line character "\n" which inserts a new line. Pythona = "Geeks\nfor\nGeeks" print(a)OutputGeeks f
2 min read
How to Print a Dictionary in Python Python Dictionaries are the form of data structures that allow us to store and retrieve the key-value pairs properly. While working with dictionaries, it is important to print the contents of the dictionary for analysis or debugging.Example: Using print FunctionPython# input dictionary input_dict =
3 min read