Skip to content

Instantly share code, notes, and snippets.

@jackeyGao
Last active June 28, 2019 01:13
Show Gist options
  • Select an option

  • Save jackeyGao/196dd1c99ba3dafa0a665d946c2f7f4f to your computer and use it in GitHub Desktop.

Select an option

Save jackeyGao/196dd1c99ba3dafa0a665d946c2f7f4f to your computer and use it in GitHub Desktop.
Python convert a string to f-string
>>> hello = 'Hello'
>>> world = 'world!'
>>> str = '{hello} {world}'
>>> str.format(**locals())
# or
>>> str = '{hello.upper()} {world.upper()}'
>>> eval(f'''f"{str}"''')
'HELLO WORLD!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment