Confused with Functions and decorators
Ok so i am trying to learn this and i do not understand some of it. I also tried to searched the web but i couldnt find any answers. 1. I dont understand when i will need to use a function that returns another function. eg def outer(): def inner(): x = 5 return inner why not just use inner and forget about the whole outer function? 2. This is more yes or no question when you pass in a func into another func as a parameter do you need to specify the parameter that the func is being passed into as func? eg def passinto(func) pass def param(): x = 5 p = passinto(param) also is this above statement correct? -- https://mail.python.org/mailman/listinfo/python-list
Re: Confused with Functions and decorators
oh yeah i forgot about the decorators. Um say that you wanted to decorate a function with the outer() func you would just put @outer on top of it? And this is the same as passing another func into the outer func? and also with the first example you say x is in the scope when is was created can you define x in the outer func and refer to it in the inner func? -- https://mail.python.org/mailman/listinfo/python-list
Re: Confused with Functions and decorators
Ok thanks man I have never used forums and stuff before but it is great help thank you so much. -- https://mail.python.org/mailman/listinfo/python-list
Re: Confused with Functions and decorators
ok I seem to very confused about this. Is there like a page or web page that like completely sums this up so i can study. I am going to look up 'functions in python'. I am not sure if this is what we a talking about as a whole here but I'am sure that I'll find something. I am all good with decorators just I can't wrap my head around why we need a function within a function? like the outer and inner thing. for example if we have like: >>> def multi_squared(func): def multi(): return (func)**2 return math >>> >>>@math #does decorator go here or when we call the function??? >>>def number(x, y): return x*y is this above example valid? like this is the stuff i am stuck on like i know what todo or i think i know but not sure if it is perfectly valid. I am going to search for something now but if you know where i could find something like this or if you could sort it out that would be great. -- https://mail.python.org/mailman/listinfo/python-list
Re: Confused with Functions and decorators
Ok thanks so much i really want to get good. I also found this MIT open course lectures for python. Is this good to use as a source of learning? I think it would because it is MIT. -- https://mail.python.org/mailman/listinfo/python-list