9 月 222020
#自定义函数,重量克转化为千克
def g2kg(g):
kg = g / 1000
return str(kg) + 'kg'
#调用函数并赋值变量
result = g2kg(2500)
#打印变量
print(result)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
2.5kg
PS C:\Users\harveymei>