Reputation: 9
Learning from the book "python crash course second edition". I'm getting syntaxerrors for the code that is being taught inside the book and don't understand why.
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
message = f"My first bicycle was a {bicycles[0].title()}."
print(bicycles[0].title())
print(message)
Any reasons why? Is the book incorrect?
I'm using sublime text on a MacBook Pro. Thanks!
Upvotes: 0
Views: 64
Reputation: 9
You might be using python version 3.6 and below, message = f"My first bicycle was a {bicycles[0].title()}." 'f' strings are introduced in python 3.6 and above. So check you current python version, if your version below 3.6 then surely that's the error's route cause. Learn more about python 'f' string visit https://www.python.org/dev/peps/pep-0498/
Upvotes: 1
Reputation: 2148
The code runs OK for me.
The syntax with f
(f"My first bicycle was a {bicycles[0].title()}."
) is new from Python 3.6.
Check that your Python version is recent enough. It's also useful to post the exact error you get.
Upvotes: 0