• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
PythonForBeginners.com

PythonForBeginners.com

Learn By Example

  • Home
  • Learn Python
    • Python Tutorial
  • Categories
    • Basics
    • Lists
    • Dictionary
    • Code Snippets
    • Comments
    • Modules
    • API
    • Beautiful Soup
    • Cheatsheet
    • Games
    • Loops
  • Python Courses
    • Python 3 For Beginners
You are here: Home / Basics / Print Without Newline in Python

Print Without Newline in Python

Author: Aditya Raj
Last Updated: March 14, 2022

While programming, we use the print() function to print a string or a value to the standard output. Normally, each print() function prints a value on a new line. However, we can change this behavior of the function. In this article, we will see how we can print without newline in python.

How to Print Without Newline in Python?

The print() function takes various input arguments along with the values to print. Normally, when we do not pass any additional parameters to the print() function, it prints values on a newline every time the function is called. You can observe this in the following example.

print("This is the first line.")
print("This is the second line.")
print("This is the third line.")
print("This is the fourth line.")

Output:

This is the first line.
This is the second line.
This is the third line.
This is the fourth line.

We can change this behavior of the print() function by using the parameter “end”. The parameter “end” is used to specify the character. The print() function prints after printing the values passed to it. The default value for the parameter “end” is “\n” i.e. newline character. This is why the print() function prints a newline character after printing the values. Due to this, the next print() statement always prints values on a new line. 

You can pass any character as an input argument for the parameter “end”. The print() function, when executed, will always print the character passed as the input argument after printing the actual values. For instance, you can pass the period  “.” character to the parameter “end” as an input argument. This will make the print() function print a period after printing the actual input values. You can observe this in the following example.

print("This is the first line.", end=".")
print("This is the second line.", end=".")
print("This is the third line.", end=".")
print("This is the fourth line.", end=".")

Output:

This is the first line..This is the second line..This is the third line..This is the fourth line..

To print a comma after each print statement execution, you can pass “,” as the input argument to the print() function as follows.

print("This is the first line.", end=",")
print("This is the second line.", end=",")
print("This is the third line.", end=",")
print("This is the fourth line.", end=",")

Output:

This is the first line.,This is the second line.,This is the third line.,This is the fourth line.,

Similarly, you can pass a hyphen, &, *, $, @, !, parentheses, brackets, or any other character to the parameter “end”. You can even pass the alphabets and numbers as input arguments to the print() function. The print() function will simply print the character passed to the parameter “end” after printing the actual values without printing to a newline.

Conclusion

In this article, we have discussed how we can print without newline in python. You can also modify the appearance of strings while printing them by using string formatting in python. To learn more about strings in python, you may read this article on string concatenation.

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Enroll Now

Filed Under: Basics Author: Aditya Raj

More Python Topics

API Argv Basics Beautiful Soup Cheatsheet Code Code Snippets Command Line Comments Concatenation crawler Data Structures Data Types deque Development Dictionary Dictionary Data Structure In Python Error Handling Exceptions Filehandling Files Functions Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pip Pyspark Python Python On The Web Python Strings Queue Requests Scraping Scripts Split Strings System & OS urllib2

Primary Sidebar

Menu

  • Basics
  • Cheatsheet
  • Code Snippets
  • Development
  • Dictionary
  • Error Handling
  • Lists
  • Loops
  • Modules
  • Scripts
  • Strings
  • System & OS
  • Web

Get Our Free Guide To Learning Python

Most Popular Content

  • Reading and Writing Files in Python
  • Python Dictionary – How To Create Dictionaries In Python
  • How to use Split in Python
  • Python String Concatenation and Formatting
  • List Comprehension in Python
  • How to Use sys.argv in Python?
  • How to use comments in Python
  • Try and Except in Python

Recent Posts

  • Count Rows With Null Values in PySpark
  • PySpark OrderBy One or Multiple Columns
  • Select Rows with Null values in PySpark
  • PySpark Count Distinct Values in One or Multiple Columns
  • PySpark Filter Rows in a DataFrame by Condition

Copyright © 2012–2025 · PythonForBeginners.com

  • Home
  • Contact Us
  • Privacy Policy
  • Write For Us