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
Daniel Sayre
884 Points5 vs 'dogs'?
Towards the end of the strings video, Kenneth states that python knows 5 is a string so it does not need any quotes. So why does he add single quote to 'dogs'?
Daniel Sayre
884 PointsIt starts around 7:21 of the Strings video. Here is the URL: https://teamtreehouse.com/library/python-basics/python-data-types/strings
1 Answer
Blaine McCarthy
17,030 PointsIf you take the quotes out of 'dogs', Python will think you've defined a variable named "dogs" and are trying to pass it. Since we haven't defined a variable named "dogs", Python will have nothin to pass to the message via format.
dogs = "Spot and Lou"
message = "The names of the dogs are {}".format(dogs)
Will generate "The names of the dogs are Spot and Lou".
dogs = "Spot and Lou"
message = "The names of the dogs are {}".format('dogs')
This will cause the message to be "The names of the dogs are dogs." Because you're giving Python a string to pass - and it knows that because its in quotes.
Blaine McCarthy
17,030 PointsBlaine McCarthy
17,030 PointsCan you link to the video? I can't see / don't know where to look to find out what step you're in.