How to print new line in python

In Python, you can print a new line using the following methods:

  1. print() function with a newline character:

    print("Hello", end="\n")

    The end parameter is used to specify the character to print after the output. By default, it's a space (" "). By setting it to "\n", you're telling Python to print a newline character.

  2. print() function with a newline string:

    print("Hello\n")

    You can simply print a string that contains a newline character ("\n").

  3. print() function with a separate print() statement:

    print("Hello")
    print()

    You can print a statement, followed by an empty print() statement, which will print a newline character.

  4. Using the os module:

    import os
    os.system("echo Hello\n")

    This method is less common and is used when you need to print a newline character in a specific context, such as when working with shell commands.

  5. Using the print() function with a separator:

    print("Hello", "World", sep="\n")

    The sep parameter is used to specify the separator between the output. By setting it to "\n", you're telling Python to print a newline character between the output.

Remember that in Python 3.x, the print() function is a function, whereas in Python 2.x, it's a statement.