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 trialZachary Kaufman
1,463 PointsDict Syntax
I was just wondering if you HAVE to write dictionaries as {"name": "Zach", "age": 15} or if you can do something like
my_dict = {
"name": "Zach",
"age": 15
}
does Python allow me to write dictionaries like that or do I have to do it all on one line? Thanks!
1 Answer
Alexander Davison
65,469 PointsSo yes, you can do
my_dict = {
"username": "xela888",
"language": "Python"
"state": "CA"
}
Zachary Kaufman
1,463 PointsThanks!
john larson
16,594 PointsI like that, it's javascripty. I wondered the same thing but figured it wouldn't work cause Python is all about indenting (which I really like but takes some getting used to) I suppose I could have just tried it but...I didn't.
Zachary Kaufman
1,463 PointsZachary Kaufman
1,463 PointsSorry about the weird formatting, when I first wrote this it out the second example all on one line again...