开发者

python filename=None

开发者 https://www.devze.com 2023-04-12 13:13 出处:网络
I\'m new to Python. I heard that when we initialize a function we should always st开发者_如何学JAVAart by self but I didn\'t get the fileName=None. What does this argument stand for?

I'm new to Python. I heard that when we initialize a function we should always st开发者_如何学JAVAart by self but I didn't get the fileName=None. What does this argument stand for?

def __init__(self, fileName=None):


It is a default value for the parameter fileName. If the caller does not specify a value, it will be set to None. This code demonstrates it:

def foo(bar=None):
    print bar

foo() # will print the default value
>> None
foo(1) # will print the given value
>> 1

Note that default parameter values in Python are tricky, because the expression will be evaluated exactly once, when the function definition is executed.

0

精彩评论

暂无评论...
验证码 换一张
取 消