How to Skip a Line in Python? [4 Ways]

Are you struggling with how to skip lines in Python? Let me tell you four different ways to skip a line in Python with some illustrative examples.

In this Python article, I will explain all the different approaches to skip a line in Python, such as using \n, if statement, pass statement, etc., in detail.

Skipping a line in Python is a common task, mainly when we want to represent our data to someone. Let’s see:

How to Skip a Line in Python Using If Statement

In this section, I will explain how to skip a line using an if statement in Python. The if statement is a conditional statement in Python and works if the statement is True.

Here is the full code of Python to skip a line using an if statement.

USA_cities = ['Dallas', 'Los Angeles', 'New York', 'Chicago']
for i in USA_cities:
    if i=='New York':
        print()
    print(i)

If i is ‘New York,’ this line will print an empty line since the print() function is called without the “any arguments”.

if i=='New York':
print()

Output:

Dallas
Los Angeles

New York
Chicago

To see the result refer to the screenshot shown below.

how to skip a line in python code

How to Skip a Line in Python using \n (Newline character)

In Python, a newline character (\n) indicates the end of the line. So, we can put the \n in the text to skip a line. This is the most common way to skip lines in Python.

You can see below the code of Python to skip a line using \n.

print("Sucess is a Journey\nNot a Destination")

Output:

Sucess is a Journey
Not a Destination

Refer to the screenshot below. It shows the output.

How to skip a line in Python input

Python Program to Skip a Line Using Pass Statement

One of the simplest ways to skip a line in Python is by using the pass statement, which acts as a placeholder. It allows you to bypass a code line without causing any Python SyntaxError.

Here is the complete code to skip a line using a pass statement in Python.

Employee_Name = ['John', 'Lynne', 'Alex', 'Ellena', 'Joe', 'Jonny']
for i in Employee_Name:
  if (i=='Alex'):
    pass
  else:
    print(i)

Output:

John
Lynne
Ellena
Joe
Jonny

You can see the output in the image shown below.

How to skip a line in Python using pass statement

Skip a Line in Python Using the Return Statement

This is another approach to skip a line in Python using the return statement in a function.

Here is the complete Python code to skip a line using the return statement.

def USA_car_brands(x):
  if (x == "Cadillac"):
    return
  else:
    print(x)
    return
  
car_brands = ["GMC", "Tesala", "Cadillac", "Ford", "Cadillac", "Jeep" ]
for i in car_brands:
  USA_car_brands(i)

Here, I have given input to the function: Cadillac, which skips printing that particular brand and returns from the Python function without taking any further action. For any other car brand, it prints the brand name.

if (x == "Cadillac"):
    return
  else:
    print(x)
    return

Output: The screenshot below shows the result after executing the Python code.

Python program to skip a line using return statement

Skip a Line in Python Using the Continue Statement

The continue statement in Python is used to skip the remaining code inside a loop for the current iteration only.

We use the ‘continue‘ statement to skip the execution of the current iteration of the loop. To avoid error, do not use this statement outside the loop. This may cause an error in Python.

Using the continue statement, you can see the Python’s full code to skip a line.

for val in "California":
    if val == "i":
        continue
    print(val)

Output:

C
a
l
f
o
r
n
a

Refer to the screenshot below. It gives the output after the Python code gets executed.

Skip a line in Python using continue statement

Conclusion

I hope this Python tutorial helps you to understand how to skip a line in Python using methods with various examples like if statement, \n, pass, return, and continue statement.

Choose which method you would like to use to skip a line in Python, depending on your requirements.

You may also like to read: