Return

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:31 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
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 }}