Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

꼬물꼬물 개발자

Functions 본문

Python

Functions

한고운 2024. 8. 22. 00:07

# Functions
def say_hello():
  print("hello how r u?")

say_hello()

# Indentation
def say_bye():
  print("bye bye")
  say_hello()

say_bye()

# Parameters
def say_hello(user_name):  # user_name = parameter
  print("hello", user_name, "how are you?")

say_hello("gowoon") # gowoon = argument (data)
say_hello("nico")
say_hello("lynn")
say_hello("ralph")

# Multiple Parameters
def say_hello(user_name, user_age): 
  print("hello", user_name)
  print("you are", user_age, "years old")

say_hello("gowoon", 42

# Default Parameters
def say_hello(user_name = "anonymous"):
  print("hello", user_name)

say_hello()



# practice (계산기)


def plus(a = 0, b = 0):
  print(a + b)

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

def multiply(a = 0, b = 0):
  print(a * b)

def divide(a = 0, b = 1):
  print(a / b)

def power_of(a = 0, b = 2):
  print(a ** b)

plus(1, 2)
minus(3, 4)
multiply(5, 6)
divide(7, 8)
power_of(9, 2)

plus()
minus()
multiply()
divide()
power_of()


'Python' 카테고리의 다른 글

while  (0) 2024.08.30
input, and, or  (0) 2024.08.29
if, else, elif  (0) 2024.08.23
Return  (0) 2024.08.22
Datatype  (0) 2024.08.21