avoid string concatenation

このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。

Metadata

ID: python-best-practices/avoid-string-concat

Language: Python

Severity: Warning

Category: Performance

Description

Concatenation of multiple strings is not efficient and make the code hard to read and understand.

Instead of concatenating multiple strings, use an f-string or a format string.

Learn More

Non-Compliant Code Examples

"my" + awesome + "string"
plop = "super" + "awesome" + "text"

Compliant Code Examples

"my {0} string".format(awesome)
f"my {awesome} string"
plop = "superawesometext"

function(
    tags = (
    user_tags
    + s.get("tags", [])
    + [
        f"schedule_id:{s['_id']}",
        f"schedule_name:{s['schedule_name']}",
        f"git_ref:{schedule_git_ref}",
    ]
)
)

ROOT = Path("/tmp")
my_path = ROOT / "mydir" / "subdir"
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: Cyril-Bouchiat/add-vm-package-explorer-doc