I'm new to programming and am having a little trouble understanding the lambda function in Python. I understand why it's used and its effectiveness. Just having trouble learning to apply it. I've read a guide and watched a lecture on using lambda as an argument. I've tried using the map function. Not sure if that's the correct approach, but this is my broken code in its most basic form:
def Coord(x, y, z=lambda: z*2 if z < x or z < y else z)):
print(z)
Coord(10,20,30)
Coord(10,20,12)
Coord(10,20,8)
Needs to return 30, 24, and 32, respectively. Working code without using lambda:
def Coord(x, y, z):
while z < x or z < y:
z*=2
print(z)
zis a function, so you probably don't want to print it, but rather its return value when called:print(z()). However,zin the body of the function will also refer to the argument passed toCoord(that is, to itself), so it's not clear where the actual value you want is coming from.