In most languages, including Python, the true value of a variable can be used implicitly in conditions expressions i.e:
is_selected = True
If is_selected:
#do something
Is it possible to create functions that it's arguments behave similarly?
For example, if I had a sort function named asort
that takes the argument ascending
The standard way of calling it would be:
asort(list, ascending=True)
What I'm envisioning is calling the function like:
asort(list, ascending)
Edit: The behavior I'm looking for is a little different than default arguments.
Maybe sorting is a bad example but let's stay with that, suppose my asort
function has a default=False for the ascending argument
def asort(list, ascending=False):
if ascending: #no need to =True here
#sort ascending
Else:
#sort descending
If I want to sort ascending, I must use asort(alist, ascending=True)
What I'm wondering is if there is a way to call the non-default ascending asasort(alist, ascending)