Skip to main content
added 147 characters in body
Source Link
warvariuc
  • 60.1k
  • 45
  • 183
  • 234

Python 3.6 has introduced f-strings:

print(f"foo is {bar}.") 

Old answer:

Since version 3.2 Python has str.format_map which together with locals() or globals() allows you to do fast:

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >>> bar = "something" >>> print("foo is {bar}".format_map(locals())) foo is something >>> 

Since version 3.2 Python has str.format_map which together with locals() or globals() allows you to do fast:

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >>> bar = "something" >>> print("foo is {bar}".format_map(locals())) foo is something >>> 

Python 3.6 has introduced f-strings:

print(f"foo is {bar}.") 

Old answer:

Since version 3.2 Python has str.format_map which together with locals() or globals() allows you to do fast:

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >>> bar = "something" >>> print("foo is {bar}".format_map(locals())) foo is something >>> 
Source Link
warvariuc
  • 60.1k
  • 45
  • 183
  • 234

Since version 3.2 Python has str.format_map which together with locals() or globals() allows you to do fast:

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) >>> bar = "something" >>> print("foo is {bar}".format_map(locals())) foo is something >>>