DEV Community

loading...

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

Collapse
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 := pattern.search(data)) is not None:
    # Do something with match
Enter fullscreen mode Exit fullscreen mode
Collapse
vickilanger profile image
Vicki (she/her) Author

Neat. I’ve never seen that before.