+ 1
New line
If you can use “”” what’s the point of \n
3 odpowiedzi
+ 1
So you want to know what's the point of using is \n if you can type multiline using """ without using \n
Here are the things which \n can achieve
1.print(Hi, end='\n') --> the default end character in print() is the \n and not """
2. Even the """ which you are taking about is stored as \n. Don't believe me run the following code in your python shell.
>>> a ="""
I
am
a
multiline
string"""
>>> a
Output:
'\nI\nam\na\nmultiline\nstring'
see """ uses \n
\n is a newline character and it is officially a escape character in python . So your """ uses it to achieve the newline
>>> print('\nI\nam\na\nmultiline\nstring')
Output:
I
am
a
multiline
string
CONCLUSION:
Note """ can only be used to create a newline in multiline string or comment.
But \n can be used to create a newline at any place.
0
Got it! Thank you!
0
Ezra Demiss Great. I am glad that my answer helped you.