Some open source I've been using has the below line as a function declaration:
def parse_query(query=nil, options={}, models=nil)
What effect do the "equals" symbols have on the statement? Does it just make the parameters optional?
Some open source I've been using has the below line as a function declaration:
def parse_query(query=nil, options={}, models=nil)
What effect do the "equals" symbols have on the statement? Does it just make the parameters optional?
It sets the default value of the parameter, if the person calling the function does not specify one.
Similar to Python and C++, the equals sign in the parameter list lets you specify a default parameter. For example, in Python:
def hello_world(message="Hello World"):
print "message = "+message
Calling this function like this:
hello_world()
Will result in:
message = Hello World
But calling the function like this:
hello_world("changed default")
results in:
message = changed default