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

Static methods in Python example

Static methods are almost similar to normal methods inside a class but the only difference is static methods can be called from out side the class without initializing the object of that class.This means a static method can be called without using an object, it can be called using CLASSNAME.STATIC_METHOD_NAME.

Lets see Static methods example

1) Static method example using @staticmethod

class Currency_convert:

    # create Dollar_Ringgit_convert static method
    @staticmethod
    def Dollar_Ringgit_convert(doll):
        return doll * 4.35

print('Dollar to Ringgit Convert :', Currency_convert.Dollar_Ringgit_convert(150))

2) Static method example using staticmethod()

class Currency_convert:

    # create Dollar_Ringgit_convert static method
    def Dollar_Ringgit_convert(doll):
        return doll * 4.35

Currency_convert.Dollar_Ringgit_convert = staticmethod(Currency_convert.Dollar_Ringgit_convert)

print('Dollar to Ringgit Convert :', Currency_convert.Dollar_Ringgit_convert(150))

static methods in python