:= A New Assignment Symbol in Python
Nisrin Dhoondia
Data Scientist | Machine Learning | Deep Learning | Software Development | Fresher Robotics Programmer |
Unlike other programming languages Python is a Dynamic Typing programming language, whereby the datatype of the variable is determined during runtime and is not bound or fixed. This makes it possible for the changes in the variable type and its value in the program. Besides, unlike Static Typing language there is no requirement in Python for explicitly declaration of the variable rather just assigning a value to a variable identifier creates the variable.
Assigning a value to variable identifier:
The assignment statement doesn’t return a value, so for example when the above assignment statement is executed the Python interpreter doesn’t print “Hello Pythonistas” or integer 4.
However, in Python 3.8, a new assignment symbol := was introduced that not only assigns a value to a variable identifier and creates a variable in the program but also prints the value assigned. As seen below:
The new assignment symbol := works in the print() function too, by not only assigning a value to a variable identifier and printing the value assigned but also creates a variable in the program. As seen below:
Besides, new assignment symbol := also not only allows assigning a value to a variable identifier in an expression that returns a value, but also creates a variable in the program. As seen below: