In Python, there are various situations where you may need to skip a line. Skipping a line is essential in formatting a program or creating a space between statements. In this tutorial, we will show you how to skip a line in Python.
Steps on How to Skip a Line in Python
Step 1: Using the print() Function
The easiest way to skip a line in Python is to use the print() function with the newline character (\n). The newline character tells Python to move the cursor to the next line. Here’s an example:
1 |
print("Hello World!\n") |
Output:
Hello World!
Step 2: Using the \n Escape Sequence
You can also use the \n escape sequence to skip a line in Python. This works by placing the \n at the end of the string. Here’s an example:
1 |
print("Python \nTutorial") |
Output:
Python Tutorial
Step 3: Using the print() Function with Triple Quotes
You can also use triple quotes to create a multi-line string, and use the print() function to print it. Here’s an example:
1 2 |
print("""Hello World""") |
Output:
Hello World
Conclusion
You now know three ways to skip a line in Python – by using the print() function with the newline character, the \n escape sequence, and the print() function with triple quotes. Try using them in your next Python project!
1 2 3 4 |
print("Hello World!\n") print("Python \nTutorial") print("""Hello World""") |