-
53 - (파이썬) 함수 리턴과 5-1절 확인 문제study with Q - 파이썬 2024. 6. 10. 22:11
def f(x) : #값을 들고 돌아가슈 return x+1 print(f(10)) print(f(20)) >>> 11 21
def f(x) : #return 뒤에 아무 값도 넣지않으면 return # None을 들고 돌아가게 됨 print(f(10)) print(f(20)) >>> None None
#함수 사용해보기
: 요론 모양
def 함수(매개변수): 변수 = 초기화 #처리 #처리 처리 #함수 처리 return 변수
start부터 end까지 더하는 함수
def sum_all(start, end): output = 0 for i in range(start, end+1): output += i return output print(sum_all(1, 10)) print(sum_all(1, 100)) >>> 55 5050
#확인문제
더보기더보기def f(x): return 2*x+1 print(f(10)) def g(x): return x**2 + 2*x + 1 print(g(10)) >>> 21 121
def mul(*values): val = 1 for i in values: val *= i return val print(mul(5,7,9,10)) >>> 3150
'study with Q - 파이썬' 카테고리의 다른 글
55 - (파이썬) 메모리 구조: global 키워드 (0) 2024.06.15 54 - (파이썬) 메모리 구조 : 스택과 힙, 함수와 결합할 때 (1) 2024.06.15 52 - (파이썬) 기본 매개변수 (0) 2024.06.10 51 - (파이썬) 가변 매개변수 함수 (0) 2024.06.03 50 - 함수, 매개변수 기본 (0) 2024.06.02