"함수 정의"의 두 판 사이의 차이

65번째 줄: 65번째 줄:
show_answer()
show_answer()
# 42
# 42
</source>
==Perl==
[[분류:Perl]]
<source lang='Perl'>
sub greet() {
print "hello\n";
}
greet();
</source>
</source>



2018년 1월 15일 (월) 21:18 판

function
def

1 Bash

greet() {
	echo 'hello'
}
greet
# hello
function greet() {
	echo 'hello'
}
greet
# hello

POSIX 호환 전용 셸의 경우 greet() { ... } 형태의 함수만 지원한다.

2 JavaScript

function greet() {
	console.log("hello");
}
greet();
// hello
var greet = function() {
	console.log("hello");
}
greet();
// hello

3 PHP

function greet() {
	print("hello");
}
greet();
# hello

4 Python

def greet():
	print('hello')

greet()
# hello
def show_ answer():
	print(42)

show_answer()
# 42

5 Perl

sub greet() {
	print "hello\n";
}

greet();

6 Ruby

def greet
   puts "hello" 
end

greet
# hello

7 같이 보기

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