Not sure if this has been discussed here before, but this is the idea.
We all know that when calling a function, if you have a variable that’s named the same as one of the function’s arguments, you have to write it out fully. Like this:
def my_function(a, b):
pass
a = 1
b = 2
my_function(a=a, b=b)
When there are a lot arguments and argument names are long, this can be very verbose. What if we could make this shorter and just write:
my_function(.a, .b)
my_function(a=a, b=b) # these two lines do the same thing
This idea is actually from Systemverilog. I use the feature all the time. Hope python can have a similar feature. It can apparently make a lot of function calls with keyword arguments a lot shorter and cleaner.
There is no such limitation. The variable a and b will be different than the global a and b as they are scoped differently. Python will not be confused by this and it will run perfectly fine.
In the example below, we can see that we can pass global a and b, manipulate the content in the function, print it, and the global a and b will not be affected.
def my_function(a, b):
a += 1
b += 1
print(a, b)
a = 1
b = 2
my_function(a, b)
print(a, b)