menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

The Walrus...
source image

RealPython

4w

read

204

img
dot

Image Credit: RealPython

The Walrus Operator: Python's Assignment Expressions

  • Python’s walrus operator (:=) enables you to assign values to variables seamlessly as part of an expression.
  • It helps to streamline constructs like loops, conditionals, and list comprehensions making Python more concise and readable.
  • The walrus operator is helpful in the situation where you want to avoid repetitive function calls or calculations.
  • Regular assignments prevent programming errors by not returning a value, while assignment expressions return the assigned value.
  • Guido van Rossum accepted PEP 572 in July 2018, and the walrus operator was implemented and made available in the first alpha release of Python 3.8.
  • Named expressions, assignment expression operator, and colon equals operator are some of the terms used to refer to the walrus operator.
  • A statement in Python is a unit of code. An expression is a special statement that can be evaluated to some value.
  • PEP 572 details the syntax and usage of the walrus operator, which was written by Chris Angelico in 2018.
  • The walrus operator enables you to write compact and efficient code, especially when working with complex conditions and loops.
  • Emily Morehouse implemented the walrus operator, which is now governed by an elected steering council.

Read Full Article

like

12 Likes

For uninterrupted reading, download the app