print newline in python code example
Example 1: print new line python
print("\n")
Example 2: how to print a newline in python
# To print a newline in python Python has a special charecter as \n with a
# string.
print("Hi\nHow are you")
#The output of This program is:
Hi
How are you
# But if you just print a new line like this:
print("\n")
# The output of this program is Two newlines:
# It printed two newlines because if i say print("hi") and then print("hello")
# Python prints them in seperate lines.This means that Python automatically
# generates a newline with the print statement. So if we print("\n") Python
# automattically generates a newline because of the print statement and then
# it prints a newline which gives us two blank lines. So print("\n") therefore,
# gives you two blank lines.
# If you have to print a blank single newline you have to use print() or
# print("") What this blank print statement does is Python automatically
# generates a newline because of the print statement and then you print
# nothing. So print() or print("") gives you a blank single new line.
Example 3: write code in new line python
s = 'https://ja.wikipedia.org/wiki/'\
'%E3%83%97%E3%83%AD%E3%82%B0%E3%83'\
'%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E'
print(s)
# https://ja.wikipedia.org/wiki/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E