티스토리 뷰

How to write a Function in Python

파이썬에서 함수를 작성하는 방법

 

다른 언어들처럼 body 부분을 { } 대괄호 등으로 묶어서 표현하지 않는다.

들여쓰기 (Tab)하여 function을 작성하면 된다.

	print("How to write a function in Python")
print("This is not working")

첫번째 줄에 작성된 것처럼 들여쓰기를 해야 함.

두번째 줄처럼 Tab하지 않고 작성하면 작동하지 않음.

 

 

 

 

How to create Function in Python

파이썬에서 함수를 만드는 방법

my_test()

괄호 ()가 Function의 실행 기능을 함.

 

 

 

 

How to write print function in Python

파이썬에서 프린트 함수를 작성하는 방법

def minus(a, b):
	print(a - b)

minus(3, 4)
def bucket_list(yours="one success"):
	print("My bucket list is", yours)
    
bucket_list()
>>> My bucket list is one success

bucket_list("that working for Amazon")
>>> My bucket list is that working for Amazon

댓글
최근에 올라온 글
페이지 이동 안내

보던 글 목록 : 브라우저 뒤로 가기 메인 화면 : 좌측 상단 아이콘
🍍 The GOAL: AI expert에 가까워지는 중

🍍 I am becoming AI expert who can develop cool things by coding.