魔法のメモ

CG N GAME BLOG

Python_15.速習_関数

def say_hello():
  print('皆さん、こんにちわ')
say_hello()
皆さん、こんにちわ
 
def say_hello2(name):
  print(f'{name}さん、こんにちわ')
say_hello2(name='ランディー')
ランディーさん、こんにちわ
 
def calc_square(side):
  return side*side
result=calc_square(side=10)
print(result)
100
 
def calc_tri(base,height):
  return base*height/2
calc_tri(base=10 ,height =3)
15.0
 
def calc_tri(base=10,height=3): #デフォルトの値を設定できる
  return base*height/2
print(calc_tri(base=100 ,height =30))
print(calc_tri())
1500.0
15.0