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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -