Algorithm


  1. Initialize Variables:

    • Set up any necessary variables for your program.
  2. User Input:

    • If required, take any input from the user.
  3. Print Output Without Newline:

    • Use the print function with the end parameter to specify an empty string as the character that separates printed items. This will prevent the default newline character.

 

Code Examples

#1 Code Example- Python Programing of Printing without Newline

Code - Python Programming

# Printing text without newline (Python 3.x)
print("Welcome to", end ="")
print("Python Tutorial")

# Printing text without newline
# Add space between each text
print("Welcome to", end =" ")
print("Python Tutorial")

# Printing text without newline (Python 2.x)
print "Welcome to",
print "Python Tutorial"

#Import sys module
import sys
sys.stdout.write("Welcome to")
sys.stdout.write("Python Tutorial")
Copy The Code & Try With Live Editor

#2 Code Example- Default Behaviour of Printing

Code - Python Programming

print("Welcome to")
print("Python Tutorial")
Copy The Code & Try With Live Editor

#3 Code Example- Print Without a New Line in Python 3.x

Code - Python Programming

# Printing text without newline (Python 3.x)
print("Welcome to", end ="")
print("Python Tutorial")
Copy The Code & Try With Live Editor

Output

x
+
cmd
Welcome toPython Tutorial

#4 Code Example- Print Without a New Line in Python 2.x

Code - Python Programming

print "Welcome to",
print "Python Tutorial"
Copy The Code & Try With Live Editor

Output

x
+
cmd
Welcome to Python Tutorial

#5 Code Example- Print List of Strings in a Newline using Loop

Code - Python Programming

mystring = ["apple","mango","grape","berry"]
for x in mystring:
    print(x, end = " ")
Copy The Code & Try With Live Editor

Output

x
+
cmd
apple mango grape berry
Advertisements

Demonstration


Python Programing Example to Print Output Without a Newline-DevsEnv