Perhaps beginners like me should not be doing a MIT course, but anyway,
how do you call a function in Python ?
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
By it's name?
Not quite sure I understand the question!
Thanks, I forgot to define it first !
Suppose we have a function like this:
To call it, you would do f(). If the function takes arguments like the one below:
def g(x, y, z):
Then you would do g(5, 3, 5), to correspond to the argument list. Note that if you're calling an instance method like the one defined below:
def make_tea(self, amount):
Make sure you don't pass 2 arguments. The self argument here is automatically provided. Example:
myTP = Teapot()
myTP.make_tea(5) # Notice that we don't pass the self argument in
Should be a good crash course.
Not the answer you are looking for? Search for more explanations.
So, I put in a separate file and just
It's just that I'm trying to get to grips with defining and running a function using my Linux machine (just shell or python shell, no idle)
Because I'm doing L4 problem 1 functions and trying
def a (x):
return x + 1
then calling it with
And of course that works now because previously I was calling it while still within the function, so got error (python shell)
Additionally though I am not entirely sure what the above call is actually doing, presumably calling the function 'a' 3 times, which (again presumably) , as the function adds 1 to 'x', simply adds 1 to x 3 times with the value of x incrementing each time
Perhaps now though I am sure.
Cracking open the a(a(a(6))), it looks like this:
Call a with the argument (the result of Call a with the argument (the result of Call a with the argument 6)))