Logic

Sometimes, performing a single comparison operation on its own is not enough—perhaps we might want to perform an action if two comparisons evaluate to true at the same time. Alternatively, we might want to perform an operation only if a comparison is not true. Logic in Jinja2 helps group two or more comparisons together, allowing for the formation of complex conditions from simple comparisons. Each comparison is referred to as an operand, and the logic that's used to bind these together into complex conditionals is given in the following list:

  • and: Returns true if the left and the right operand are true
  • or: Returns true if the left or the right operand is true
  • not: Negates an operand
  • (): Wraps a set of operands together to form a larger operand
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.162.179