Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

minimallinux Group Title

Perhaps beginners like me should not be doing a MIT course, but anyway, how do you call a function in Python ? Thanks

  • one year ago
  • one year ago

  • This Question is Closed
  1. Chris2332 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    By it's name? Not quite sure I understand the question!

    • one year ago
  2. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Thanks, I forgot to define it first !

    • one year ago
  3. tyteen4a03 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Suppose we have a function like this: def f(): #code here To call it, you would do f(). If the function takes arguments like the one below: def g(x, y, z): #code here 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: class Teapot(object): def make_tea(self, amount): # code 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.

    • one year ago
  4. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    So, I put in a separate file and just f(args)

    • one year ago
  5. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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)

    • one year ago
  6. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Because I'm doing L4 problem 1 functions and trying def a (x): return x + 1 then calling it with a(a(a(6)))

    • one year ago
  7. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    And of course that works now because previously I was calling it while still within the function, so got error (python shell) Thanks all

    • one year ago
  8. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • one year ago
  9. tyteen4a03 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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)))

    • one year ago
  10. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    So I was wrong, its returns 1, 1+1,2+1 then 3 + 6

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.