#함수 : 특정 기능을 실행하는 코드

#내장 함수
'''
print() 출력 함수
input() 입력 함수
len() 길이를 알려주는 함수
sum() 합을 알려주는 함수
max() 최댓값
min() 최솟값
str() 문자열로 변환하는 함수
int() 정수
'''

#사용자 정의 함수
'''
def 함수 이름(매개변수):
    함수를 불렀을 때 실행할 명령들
'''
def hello():
    print('안녕하세요1')
    print('안녕하세요2')
    
hello()
hello()

#인자(입력 값)가 있는 함수
def print1(a):
    print('입력 값은', a)
    
print1('abc')
print1(123)

#기본값이 있는 인자
def greet(name = '홍길동'):
    print('이름은', name)
greet()
greet('박주현')

#인자가 여러 개
def add(a, b, c):
    print(a + b + c)
    print(a, b, c)
add(1, 2, 3)

#반환값이 있는 함수 return
def name(x):
    print(f'이름은 {x}입니다')
    return x

name('주현')
print(name('주현'))
x = name('민지')
print(x)

#가변인자 * 
def print_numbers(*args):
    print(args)
    for n in args:
        print(n)

print_numbers(1, 2, 3, 4)

#반환값이 여러 개
def mul(a, b, c):
    x = a * b
    y = a * c
    return x, y

mul(1, 2, 3)
print(mul(1, 2, 3))
x, y = mul(3, 4, 5)
print(x)
print(y)

print('----문제----')
def hello_name(name, age):
    print(f'이름은 {name}이고, 나이는 {age}살 입니다')

hello_name('김민지', 14)


def calc(a, b):
    C = a + b
    D = a - b
    return C, D

print(calc(10, 5))
A, B = calc(10, 5)
print(A, B)












Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: