Category: python
What are the different way to concatenate two tuples
we can concatenate two tubles using ‘+’ symbol See below example
tuple_odd = (1, 3 , 5)
tuple_even = (2, 4, 6)
tuple_int = tuple_odd + tuple_even
print( tuple_int ) # (1, 3, 5, 2, 4, 6)
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)
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))