Sunday, May 5, 2024

📑 Ternary Operators

📑 Task

1) What actions will this program perform?
2) Can you write a code snippets with ternary operators inside math calculations?

📑 Answer

1) The program generates a number (-1, 0 or 1) using a special Python module
and uses the ternary operator to call one of three anonymous functions
depending on the pseudo-random selection of the number
2) Ternary operators have lower precedence than arithmetic operators

No comments:

Post a Comment