Which programming languages allow default values for method parameters? -
i'm curious languages allow this:
method foo(string bar = "beh"){ }
if call foo this:
foo();
bar
set "beh", if call this:
foo("baz");
bar
set "baz".
php:
function foo($var = "foo") { print $var; } foo(); // outputs "foo" foo("bar"); // outputs "bar"
python:
def myfun(var = "foo"): print var
ruby:
def foo(var="foo") print var end
groovy:
def foo(var="foo") { print var }
Comments
Post a Comment