Algorithm
-
Initialize Variables:
- Set up any necessary variables for your program.
-
User Input:
- If required, take any input from the user.
-
Print Output Without Newline:
- Use the
print
function with theend
parameter to specify an empty string as the character that separates printed items. This will prevent the default newline character.
- Use the
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
#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
#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
Demonstration
Python Programing Example to Print Output Without a Newline-DevsEnv