DEV Community


Discussion on: Picking up Ruby, as a Python Dev & interview questions

akurani profile image
Amar Kurani

In Ruby, you can assign variables in an if statement. This can't be done in Python.

From Python 3.8, you can with assignment expressions. I.e, the "walrus" operator. Here's an example from PEP 572 -- Assignment Expressions:

# Handle a matched regex
if (match := is not None:
    # Do something with match
Enter fullscreen mode Exit fullscreen mode
vickilanger profile image
Vicki (she/her) Author

Neat. I’ve never seen that before.