Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Split long dictionary value over two lines

Very new to python here. How do you split a very long dictionary value over two lines while still having it appear as one line when it is output with print()? See code below.

glossary = {'dictionary' : 'A mutable associative array (or dictionary) of key and value pairs. Can contain mixed types (keys and values). Keys must be a hashable type'}

I’ve tried using triple quotes (i.e. """) with no success since I don’t think the value is technically a string.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use \ (backslash) to continue code onto the next line

e.g.

print("hello \
how are you")

would return

hello how are you

edit: you should be able to use """ as (from my understanding) it just converts it to a normal string but adds the line breaks. this wouldnt give the result you wanted but it should work

edit: just tested the above:

list = ['hi', '''thing1
thing2''']
print(list)

ouput:

['hi', 'thing1\nthing2']

that \n means newline so i would use the backslash as i mentioned above if you want the correct output

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading