4. python学习之函数学习
2020-02-29 本文已影响0人
秦城听雪

这是python自带的函数。
如何定义一个函数?
def function (arg1,arg2):
return 'something'

练习:
- 设置一个重量转换器,输入重量为20g,输出为kg。
def weightchange(a):
weight = a / 1000
print(f'输入的重量为{a}g, 转化后为{weight}kg')
weightchange(20)

def triangle(a,b):
c = (a ** 2 + b ** 2) ** 0.5
print(f'The right triangle third side\'s length is {c}')
triangle(3, 4)