3 ms·
import random some_value = 9 # return a number between 0 and, including, 100 if below_ten := some_value < 10: print(f"{below_ten}, some_value is smalle
by bjornasm 3y ago
import random
some_value = 9 # return a number between 0 and, including, 100
if below_ten := some_value < 10:
print(f"{below_ten}, some_value is smaller than 10")
Random isn't used in this function, but more importantly why would you assign the value to below_ten if the point is to just print it, why not just print some_value?
Even in the next example of the walrus operator - it is extremely contrived:
if result := some_method(): # If result is not Falsy
print(result)
Why not just:
if some_method():
print(True)