-1

Let's say this is the signature of my function:

def foo(x,y,z=0):
.
.

When I want to use this function, how can I override the value of z without changing the function or the signature?

9
  • 1
    What do you mean override? Commented Aug 21, 2016 at 13:54
  • 1
    Why would you change z's default value? The reason you change it in the first place is to be default. Commented Aug 21, 2016 at 13:55
  • Do you mean how to pass in a value for z when calling the function? Commented Aug 21, 2016 at 13:56
  • def bar(x,y,z=5): return foo(x,y,z)? Commented Aug 21, 2016 at 13:56
  • You can't. You could assign a new function object to the name foo with a different default that calls the old function object. Would that do? Commented Aug 21, 2016 at 13:56

1 Answer 1

5

Just pass value explicitly.

def foo(x, y, z=0):
    print z

foo(1,3)
>> 0 # default value

foo(1,2,5)
>> 5 # new value passed
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.