Quora Feans Quora Feans - 1 year ago 98
Python Question

Are f-strings supposed to work in Python 3.4?

Is this supposed to work in Python 3.4:

>>> a='tttt'

>>> print(f'The value of a is {a}')

Answer Source

You could at least emulate them if really needed

def f(string):
    # (!) Using globals is bad bad bad
    return string.format(**globals())

# Use as follows:
ans = 'SPAM'
print(f('we love {ans}'))

Or maybe some other ways, like a class with reloaded __getitem__ if you like f[...] syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download