What is Walrus Operator in Python

Walrus Operator is the one of the new features in python 3.8 ,it is a new method, using Walrus Operator we can assign values to variable as a part of an expression using the notation NAME := expression for example :

x_year= 2019

if (y_year:= x_year) < 2020:
    print(f"The value of y_year is {y_year} and is happend before 2020.")

here the value of x_year is assigned y_year if the condition satified(< 2020)

What is Walrus Operator in Python

Leave a Reply

Your email address will not be published. Required fields are marked *