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 Python Collections (Retired) Dictionaries Unpacking Dictionaries

Sergio Niño
seal-mask
.a{fill-rule:evenodd;}techdegree
Sergio Niño
Full Stack JavaScript Techdegree Student 22,976 Points

Unpacking Dictionaries Unexpected

my_string = "Hi, my name is {} and I live in {}."
my_string.format("Sergio", "Colomobia")
'Hi, my name is Sergio and I live in Colomobia.'

in the video kenneth got an KeyError when he put their name and location between single quotes but instead I've put double quotes and apparently it works.. why?

Myles Marcus
Myles Marcus
1,233 Points

The difference is that in the first line of my_string....you didn't put anything between the {}...in the video he does and that is why his method got a KeyError

2 Answers

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

By looking at some responses in stack overflow, simple quotes and double quotes are interchangeable (in python), they are a matter of taste. http://stackoverflow.com/questions/56011/single-quotes-vs-double-quotes-in-python

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Sergio,

As far as I know, there's no difference between single and double quotes in this case. I tried the example with single quotes without exception. Maybe there's something else he did in combination that caused the error.

I hope this helps.