Python new line
In Python, there are several ways to create a new line:
- Using the
\n
character: You can use the\n
character to create a new line. For example:print("Hello") print("\nWorld")
This will output:
Hello
World
2. **Using the `print()` function with multiple arguments**: You can pass multiple arguments to the `print()` function, separated by commas. Each argument will be printed on a new line. For example:
print("Hello", "World")
This will output:
Hello World
3. **Using the `print()` function with a string and a newline character**: You can pass a string and a newline character (`\n`) to the `print()` function. For example:
print("Hello\nWorld")
This will output:
Hello World
4. **Using the `print()` function with a formatted string**: You can use the `format()` method or f-strings to create a formatted string with a newline character. For example:
print("Hello{}World".format("\n"))
This will output:
Hello World
Or:
print(f"Hello\nWorld")
This will also output:
Hello World
5. **Using the `print()` function with a list of strings**: You can pass a list of strings to the `print()` function, and it will print each string on a new line. For example:
print(["Hello", "World"])
This will output:
Hello World
Note that the `print()` function will automatically add a newline character at the end of its output, so you don't need to add it explicitly unless you want to print multiple lines without a newline character in between.