+ 1
r before the string
Why print(r'\nHello\nWorld') its output would be \nHello\nWorld, where is the r in the beginning ? What does it mean?
6 Respostas
+ 12
For strings, there are several codes you can use to do a certain thing.
'\n' means newline, so when you write ...
print('Hello\nworld')
... it is printed in two lines.
Having the r before the string (standing for 'raw') is an order to ignore all these codes and just print everything as it is.
Basically it enters an extra '\' in front of each of these codes which will lead to them being ignored.
You could also do that by hand, writing a bunch of '\' in front of all the codes.
+ 1
Thank you, i understand now
+ 1
it will print: Hello 'whatevever the user inputs'!!!
0
Hey if u wanna get creative, use only f strings like this
0
name = input("What is your name: ")
0
print(f"Hello {name}!!")