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) Logic in Python Fully Functional

Nicholas Chedid
Nicholas Chedid
510 Points

f string formatting

I am trying to use f-string formatting like this print(f"{name}") as opposed to the .format shown in the video to try to develop cleaner Python habits. For some reason my f-string isn't working when I try it in the Workspace. Could you please write out the line of code from the video that uses .format correctly using the f-string syntax I described? Or perhaps the non .format method is not compatible with the Workspace? I'm thinking maybe it's a compatibility issue with Workspace because I just tried the following in Windows PowerShell:

name = me print(f"{name} sleeps all night and {name} works all day!")

And the output worked just fine

2 Answers

andren
andren
28,558 Points

You are using f-strings correctly, the issue is that they are a pretty recent addition to the Python language. They were added in Python version 3.6, the workspace on Treehouse still uses Python version 3.5.

So until Treehouse updates to Python 3.6 or higher you won't be able to use f-strings in the workspace or in challenges.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Good to know! :)

Thanks for providing the link andren. I'll have to brush up on my python basics. :bulb:

:dizzy:

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Nicholas,

From what I remember (and after a quick refresher with Google), Python has a print() method, but does not have a printf() method, so .format is the "cleaner" way. I'm assuming you're coming from a C type of coding background which does have a printf, but sorry, Python does not... that doesn't mean you couldn't write your own though. :smiley:

Keep Coding! :) :dizzy: