The Wayback Machine - https://web.archive.org/web/20250112142732/https://www.geeksforgeeks.org/gfact-50-python-end-parameter-in-print/
Open In App

Python end parameter in print()

Last Updated : 01 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

By default Python‘s print() function ends with a newline. A programmer with C/C++ background may wonder how to print without a 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. 

Python
# ends the output with a space
print("Welcome to", end = ' ')
print("GeeksforGeeks", end= ' ')

Output:

Welcome to GeeksforGeeks

Let’s see one more example to demonstrate the working of the end parameter. 

Python
# ends the output with '@'
print("Python", end='@')
print("GeeksforGeeks")

Output:

Python@GeeksforGeeks

Using sep and end parameter together

The print() function uses the sep parameter to separate the arguments and ends after the last argument.

Python
print('G','F', sep='', end='')
print('G')
#\n provides new line after printing the year
print('09','12','2016', sep='-', end='\n')
 
print('Red','Green','Blue', sep=',', end='@')
print('geeksforgeeks')

Output

GFG
09-12-2016
Red,Green,Blue@geeksforgeeks

Python end parameter in print() – FAQs

How to use Python end parameter in print()?

The end parameter in the print() function specifies what is printed at the end of the output. By default, it is set to a newline character (\n), which means each print() call outputs on a new line. You can change this to any other string:

print(“Hello”, end=”, “)
print(“world!”)

How to concatenate output from multiple print statements in Python?

Use the end parameter to concatenate outputs from multiple print() statements on the same line:

print("Part 1", end=" ")
print("Part 2", end=" ")
print("Part 3")

Output:

Part 1 Part 2 Part 3

Can the end parameter be used to format CSV data in Python?

Yes, the end parameter can help in formatting CSV data. By setting end to a comma or other delimiter, you can print CSV-like formatted data:

print("Name", end=", ")
print("Age", end=", ")
print("City")
print("Alice", end=", ")
print("30", end=", ")
print("New York")

Output:

Name, Age, City
Alice, 30, New York

These uses of the end parameter can enhance the control you have over output formatting in Python.

Enhance your coding skills with DSA Python, a comprehensive course focused on Data Structures and Algorithms using Python. Over 90 days, you'll explore essential algorithms, learn how to solve complex problems, and sharpen your Python programming skills. This course is perfect for anyone looking to level up their coding abilities and get ready for top tech interviews.
Join the Three 90 Challenge and commit to completing 90% of the course in 90 days to earn a 90% refund. It’s the perfect way to stay focused, track your progress, and reap the rewards of your hard work. Take the challenge and become a DSA expert in Python today


Next Article
Article Tags :
Practice Tags :

Similar Reads

three90RightbarBannerImg