String builder optimization (ARCH2071)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key python.performance.string-builder-optimization · Severity info · Category performance
Chaining many fragments with + in one expression is unreadable and allocates needless intermediate strings. Use join or f-string formatting instead.
Incorrect
Section titled “Incorrect”def label(user): return "Name: " + user.first + " " + user.last + " (" + user.role + ") - " + user.dept + "/" + user.teamCorrect
Section titled “Correct”def label(user): return f"Name: {user.first} {user.last} ({user.role}) - {user.dept}/{user.team}"Replace multi-+ chains with a single f-string or "".join([...]) call.