5

Ahead Warning! A Python newbie and quite a spoiled question ahead!

Is there a way to shorthand:

"{} blabla ... {}".format(x, y)

Into something like:

"{} blabla ... {}" % (x, y)

Using operator overloading like syntax or otherwise?

Not talking about old style string formatting which took typed %s ...

rubmz
  • 1,947
  • 5
  • 27
  • 49

2 Answers2

9

Use this in Python 3.6 or above:

f"{x} blabla ... {y}"
Dabiuteef
  • 465
  • 4
  • 14
1

You can do this. But strongly advice to not do this.

fmt = str.format
print fmt("{} blabla ... {}", x, y)

fmt here is just an example.

If ever you're planning to do this, you can give whatever name you like but make sure you don't override any existing variable/function names.

anupsabraham
  • 2,781
  • 2
  • 24
  • 35