python filename =无

时间:2011-10-13 09:05:00

标签: python

我是Python的新手。我听说当我们初始化一个函数时,我们应该始终自己开始,但我没有得到fileName=None。这个论点代表什么?

def __init__(self, fileName=None):

1 个答案:

答案 0 :(得分:2)

这是参数fileName的默认值。如果调用者未指定值,则将其设置为None。此代码演示了它:

def foo(bar=None):
    print bar

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

请注意,Python中的默认参数值很棘手,因为表达式为evaluated exactly once, when the function definition is executed