Created
January 4, 2023 20:07
-
-
Save Vigowebs/af18d5802120193c067c96f9a9d9cafb to your computer and use it in GitHub Desktop.
Walrus operator in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [1, 2, 3, 4] | |
# Without the walrus operator | |
i = 0 | |
while i < len(numbers): | |
print(numbers[i]) | |
i += 1 | |
# With the walrus operator | |
while (i := 0) < len(numbers): | |
print(numbers[i]) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment