Search code examples
python-3.xstringpycharmformat

Refactor string concatenation to format in PyCharm


Is there any way (with plugin or not) to automatically transform expressions like

a = "my fullname is " + name + " " + surname

to

a = "my fullname is {0} {1}".format(name, surname)

in PyCharm?


Solution

  • No but there is a shortcut to transform that into this:

    a = f"my fullname is {name} {surname}"
    

    Which is the Python 3 way. You can do that by clicking the blub button in the gutter when you're cursor is over it or pressing Alt + Enter.

    Read more about Intention Actions.