1

Consider i create a Class Name "Application" which accepts "frame" widget

class Application(Frame):

In Constructor/Initialisation i do

def __init__(self, master=None):

When creating Instance

root = Tk()
app = Application(master=root)

i dont Understand when creating instance i am assigning instance of class Tk() to Master . then why in initialisation we are making it "None". can Some one look into this and Explain.

Thanks in Advance

1 Answer 1

5

When you write def __init__(self, master=None): you are setting None as the default value of master. When you call Application(master=root) you are passing a value that overrides the default.

A simple example:

def foo(a=1):
    print "a is", a

>>> foo()
a is 1
>>> foo(2)
a is 2
>>> foo(a=2)
a is 2
>>> 
Sign up to request clarification or add additional context in comments.

2 Comments

Hi !! thnks for explanation. is there any rule/documentation which explains this in more detail. i got the point but technically still i am not able to understand. when i make a call to foo(with no arguments) its fine a gets default value. but when i pass some argument still it should get default value. why the default value is ignored ??
@PragRao: When you pass a value, it overrides the default value. That's what "default" means: it means its the value that is used if you don't specify any other value. You can start with the Python tutorial for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.