String equivalent = +, but existing string as appended, not appended to new line

I am using PyCharm (version 4.0.3) and I get a warning about the style. The assignment can be replaced by the extended assignment in the second line of the following code *:

abc = 'and cheese' abc = 'ham' + abc 

* - My code is not really this code, but it generates the same error. I programmatically generate two lines, and I should / would like to create the first line (second part of the English syntax) before the second line (first part of the English syntax).

But I do not know that such an extended task could do this. If the code was like this (where the first part of the desired end string can be generated first in execution order)

 abc = 'ham' abc = abc + 'and cheese' 

then I believe that the problem is trivially resolved using the + operator:

 abc = 'ham' abc += 'and cheese' 

But in the context of my problem (where the “and cheese” part is declared before the “ham”), is there a way to satisfy this warning?

+6
source share
1 answer

There are several ways to cat skin (or for cat enate lines).

You can combine with str.join , but it may be less efficient for small lists:

 abc = " ".join((abc, 'and cheese')) 

Or using the format:

 abc = "{} {}".format(abc, 'and cheese') 

But really, the right way to silence the warning is to send an error report to the IDE, because it seems that there is nothing wrong with your code (someone in the comments already indicated that it does not play in the latest version).

+3
source

Source: https://habr.com/ru/post/980777/


All Articles