Simple question in python

a=‘’‘Hello
Dylan’‘’
b=‘Hello\nDylan’
for i in a:
print(i)

While running this code in both the cases I got the following output;
H
e
l
l
o
.
.
D
y
l
a
n
My question is that wile iterating through this string why in output 2 blank lines are left between Hello and Dylan instead of 1. is the new line character i.e. \n considered as the size of 2 or is it something else?

print ends each printout with a newline character by default. For example, print("a") prints the character a followed by a newline. In the same way, print("\n") prints a newline followed by a newline. That is why you see two newlines in a row.

2 Likes

Thank you so much clearing this.