Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Y B
Y B
14,136 Points

Python multi line dictionary format and whitespace

I saw this questions on stack for how best to format a dictionary over multiple lines http://stackoverflow.com/questions/6388187/what-is-the-proper-way-to-format-a-multi-line-dict-in-python

However (I've been learning JS recently so my python syntax is a bit confused atm), I'm not sure how this works in terms of whitespace. Doesn't a new line signal the end of a statement in python so how does this work?

Thanks

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I prefer them with the } at the same indentation as the first letter in the dictionary's variable name but, as they said on SO, they're all three syntactically correct.

Newlines often signal the end of a line of instruction, yes, but they don't have to. Consider the following:

a = (1, 2
    4, 8, 16,
    9, 12, 21)

long_string = '''oaueouo
oueuoeu
oueuoeuoeuoeu
'''

Both are perfectly valid.

Y B
Y B
14,136 Points

Thanks Kenneth