+ 4

Hi,how how to use " " " triple quatation in a string in Python 3,i cant grasp it's ideal usage

27th Jun 2019, 12:07 PM
Vusumuzi Mabena
Vusumuzi Mabena - avatar
7 Answers
+ 4
To write a multiple of lines string without recieving an EOL (end of line) error, example: string1 = """hello world""" print(string1) >>output: hello world
27th Jun 2019, 12:24 PM
Mo Hani
Mo Hani - avatar
+ 3
Vusumuzi Mabena *wrong* print("hello world") >>output: EOL error while scanning *right* print("""hello world""") >>output: hello world
27th Jun 2019, 12:33 PM
Mo Hani
Mo Hani - avatar
+ 3
I basically don't use it at all. Usually I prefer to spread strings like this: print('Hello' ' world!') Usually triple quotes come up with docstrings. def f(): '''This function does: blablabla blablabla''" # And now the actual code
27th Jun 2019, 6:11 PM
HonFu
HonFu - avatar
+ 2
I really don't understand how to properly use this,can you please show me the how to write the multiple lined that produces erros ,and a right way to to right multiple lines using triple qoutes " " "
27th Jun 2019, 12:29 PM
Vusumuzi Mabena
Vusumuzi Mabena - avatar
+ 1
Ya it's just an alternative method It's up to us how we use it
2nd Jul 2019, 7:07 PM
Arnav Deshpande
Arnav Deshpande - avatar
0
""" it is generally used when you want to inspect your code on output screen""" Unlike conventional comments these docstring comments retain throughout the program run That's it!
2nd Jul 2019, 7:03 PM
Arnav Deshpande
Arnav Deshpande - avatar
0
Arnav Deshpande, Python doesn't require that you put your docstrings in triple quotes. Regular string literals work just as well!
2nd Jul 2019, 7:05 PM
HonFu
HonFu - avatar