Home » Python » Python programs

How to print spaces in Python?

Python | Printing spaces: Here, we are going to learn how to print a space/ multiple spaces in the Python programming language?
Submitted by IncludeHelp, on April 25, 2020

Example 1: A simple way to print spaces

print(' ')
print(" ")
print("Hello world!")
print("Hello         world")

Output

 
 
Hello world!
Hello         world

Example 2: Printing spaces between two values while printing in a single print statement

x = 10
y = 20

print("x:",x)
print("y:",y)

Output

x: 10
y: 20

Example 3: Give multiple spaces between two values

x = 10
y = 20

space = ' '

'''
  2 spaces would be here
  1 space after first parameter,
  1 space by using space variable
  1 space after second parameter
'''
print("Hello",space,"world")

'''
  7 spaces would be here
  1 space after first parameter,
  5 space by using space*5
  1 space after second parameter
'''
print("Hello",space*5,"world")

'''
  12 spaces would be here
  1 space after first parameter,
  10 space by using space*10
  1 space after second parameter
'''
print("Hello",space*10,"world")

# for better better understanding
# assign space by any other character
# Here, I am assigning '#'
space = '#'
print("Hello",space,"world")
print("Hello",space*5,"world")
print("Hello",space*10,"world")

# printing values of x and y with spaces
space = ' '
print("x:",space*10,x)
print("y:",space*10,y)

Output

Hello   world
Hello       world
Hello            world
Hello # world
Hello ##### world
Hello ########## world
x:            10
y:            20






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.