Ternary to If Expression
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: ternary-to-if-expression
Section titled “Sourcery refactoring id: ternary-to-if-expression”Description
Section titled “Description”Replace boolean ternary with inline if expression.
Before
Section titled “Before”protocol = is_ssl and "https" or "http"protocol = "https" if is_ssl else "http"Explanation
Section titled “Explanation”Prior to Python version 2.5 the best way to create a ternary operator was to use
and & or together in the before example.
The if expression syntax shows the intent of the code much clearer and so is preferred.