a=[1,2,3,4]
def func(x):
return x**x
b=sorted(a,func)
this line always gives a error->
TypeError: sorted expected 1 argument, got 2
in fact the syntax of sorted is sorted(iterable,key,reverse), in which key and reverse are optional, so according to this, second parameter i pass must go with key.
and when i def my own func
def func2(x,y=4,z=10):
print(x,y,z)
func2(100,200)--->output-->>100 200 10
here 200 automatically passed as y argument for func2. How does this work?