in comparisons, variables must be left

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

Metadata

ID: python-best-practices/comparison-constant-left

Language: Python

Severity: Notice

Category: Best Practices

Description

In a comparison that compare a variable with a value, put the variable on the left side of the comparison expression.

Non-Compliant Code Examples

if 1 <= i:  # use i >= 1
  pass
if 1.0 <= i:  # use i >= 1.0
  pass

Compliant Code Examples

if i >= 1:
  pass

if 0 < nextSx <= len(subject):
    px = nextPx
    sx = nextSx

if 1 in ctx:
  print("foo")
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