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 Basics (2015) Python Data Types String Formatting

troy serr
PLUS
troy serr
Courses Plus Student 160 Points

making strings

im trying to make a string using str.format and it says namerror what am i doing wrong?

strings.py
str.format ("troy")

2 Answers

Daniel Bourke
Daniel Bourke
3,870 Points

You're very close!

I think the question is asking for a name variable.

So maybe something like:

name = "{}".format( )

Where your name would be an argument in the format function (in string form of course).

troy serr
troy serr
Courses Plus Student 160 Points

I Tried typing that it came up with this: NameError: name 'troy' is not defined"

name = "{troy}".format(troy)
Daniel Bourke
Daniel Bourke
3,870 Points

Almost perfect!

Remember .format( ) will update { } with whatever is within ( ).

Example:

#name variable is updated to be Daniel
name = "{}".format("Daniel")

#example two
full_name = "{}{}".format("Daniel","Bourke")

Hope this helps!