Python print new line

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 specifies 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 new line.

  2. print() function with a newline string:

    print("Hello\n")

    This method is similar to the first one, but you're passing a string literal containing a newline character ("\n").

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

    print("Hello")
    print()

    This method is more explicit, as you're printing a new line using a separate print() statement.

  4. Using the os module:

    import os
    os.system("echo Hello && echo")

    This method is more platform-dependent and uses the os module to execute a system command that prints a new line.

Note that in Python 3.x, the print() function is a built-in function, whereas in Python 2.x, it's a statement. In Python 2.x, you can use the print statement with a newline character, like this: print "Hello\n".