Aug-26-2019, 03:16 AM
In python 3.8, we will have a new syntax
On the other hand, I also think that it would be useful if
Is that possible to have this new feature in new python version?
:=
that could assign values to variables as part of larger expression, for example,1 2 |
if (n: = len (a)) > 10 : .... |
:=
could be used in function argument, so that a local variable created inside a function could be returned **optionally**, for example,1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def func(arg1, arg2, karg1 = karg1_default, karg_return: = karg_return): ... karg_return = 3 ... return func_output # normal calling of func() without returning variable karg_return # in this way, karg_return:=karg_return is not used and karg_return is only simply a local variable in func() output = func( 2 , 3 ,karg1 = 4 ) # calling func() with using the karg_return argument # in this way, value of the local variable karg_return in func() is created and "passed" to variable a output = func( 2 , 3 ,karg1 = 4 ,a: = karg_return) print (a) # a = 3 |