Return

function with param
function with return
return

1 POSIX Shell[ | ]

_sum() {
	return `expr $1 + $2`
}

_sum 1 2
echo $?
# 3

2 PHP[ | ]

function sum(a, b) {
	return(a+b);
}
echo(sum(1, 2));
# 3

3 Python[ | ]

def sum(a, b):
	return(a+b)
print(sum(1, 2))
# 3

4 Ruby[ | ]

def sum(a, b)
	return a + b
end
puts sum(1, 2)
# 3
implicit return
def sum(a, b)
	a + b
end
puts sum(1, 2)
# 3

5 Perl[ | ]

sub _sum {
	my ($_a, $_b) = @_;
	return $_a+$_b;
}

print _sum(1, 2) . "\n";
# 3

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}