Walrus

This allows you to assign a value to a variable within an expression.


This can be useful when you need to use a value multiple times in a loop, but don't want to repeat the calculation.
This is represented by the `:=` syntax and can be used in a variety of contexts including while loops and if statements.
Added in version 3.8

numbers = [1, 2, 3, 4, 5] 

while (n := len(numbers)) > 0:
    print(numbers.pop())




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext