F-strings in Class __repr__ Method



I’m trying to set a class __repr__ method using f-strings. I know this isn’t necessary, and know how to do this using %-formatting or str.format() - I’ve not used f-strings before and wanted to try them out.

class Art:
  def __init__(self, artist, title, medium, year):
    self.artist = artist
    self.title = title
    self.medium = medium
    self.year = year
  def __repr__(self):
    return f'{self.artist}. "{self.title}". {self.year}, {self.medium}.'
class Marketplace:
  def __init__(self, listings):
    self.listings = []


girl_with_mandolin = Art('Picasso, Pablo', 'Girl with a Mandolin (Fanny Tellier)', 'oil on canvas', 1910) 


The above is returning;

File "script.py", line 9
    return f'{self.artist}. "{self.title}". {self.year}, {self.medium}.'
SyntaxError: invalid syntax

Could somebody please point out where I’m going wrong here?


Current version of this environment,

3.5.2 (default, Nov 23 2017, 16:37:01)

f-string formatting isn’t introduced until 3.6.


As always, thank you for the help - I now know how to check that if I need to.

import sys