Python Python Basics Logic in Python Fully Functional

Nicholas Chedid
Nicholas Chedid
415 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
24,431 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 128,737 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 128,737 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: