This program demonstrates how to print spaces in Python
Method 1: Using the space character
To print spaces in Python, you can use the space character ” “. Here’s an example:
print("Hello" + " " + "World")
In this example, we are using the +
operator to concatenate three strings: “Hello”, ” ” (a space), and “World”. When we run this code, the output will be:
Hello World
You can also use the *
operator to repeat the space character multiple times. Here’s an example:
print("Hello" + " " * 5 + "World")
In this example, we are concatenating three strings again, but this time we’re using the *
operator to repeat the space character 5 times. The output of this code will be:
Hello World
Note that the number of spaces in the output is determined by the number of times we repeat the space character using the *
operator.
1 thought on “How to print spaces in Python?”