Programming Leftovers
-
Paul Wise: FLOSS Activities December 2022
This month I didn't have any particular focus. I just worked on issues in my info bubble.
-
GStreamer compilation with third party libraries - Herostratus’ legacy
Suppose that you have to hack a GStreamer element which requires a library that is not (yet) packaged by your distribution, nor wrapped as a Meson’s subproject. How do you do?
-
Enrico Zini: Things I learnt in December 2022
Python's multiprocessing is prone to deadlocks in a number of conditions. In my case, the running program was a standard single-process, non-threaded script, but it used complex native libraries which might have been the triggers for the deadlocks.
-
Python: How to Use the If-Else Statement in One Line - ByteXD
Conditional statements in python are commands for controlling actions and decisions. These conditional constructs take action based on a condition. The given condition evaluates to true or false (if condition is true then take action).
In many cases, the executed action that is taken by a true condition is merely returning a value (assigning a new value to a target variable). Therefore, due to the simplicity of these types of if statements, many languages, including Python support inline if-else expressions.
In this article, you will learn how to use inline conditional expressions in Python.
The method of using if and else in the same line is usually referred to it as conditional expressions or ternary operations. The most common ternary conditional operator is ?: for many languages.
For example, the subsequent ternary expression: (a ? b : c), which returns b if a is true, or to c if the a condition is false. However, there is a different syntax for Python. Its ternary expression looks like the following: (a if condition else b), just as before, the expression returns a if condition is true, otherwise to b if condition is false.
In the later sections, we will explain how to use inline if-else expressions with examples.