/  Technology   /  Python | Print in the same line
Python | Print in thesameline

Python | Print in the same line

Python print() function default ends with a newline. Python has a predefined format when you use print(variable) then it will automatically go to next line.

 

Example 1:

 

print("i2tutorials")
print("Python")

 

Output:

 

Python | Print in the sameline

 

Example 2:

 

a = [1, 2, 3, 4]

# printing a element 
for i in range(4):
  print(a[i])

 

Output:

 

Python | Print in thesameline

 

Below example shows how to print result on the same line.

 

Example:

 

print("i2tutorials", end =" ")
print("Python")

# array
a = [1, 2, 3, 4]

# printing a element in same
# line
for i in range(4):
  print(a[i], end =" ")

 

Output:

 

Python | Print in thesameline

Leave a comment