1.python的内建函数(built-in functions)即python自带的函数,可以直接使用。
2.python自带函数的介绍参见网址:https://docs.python.org/3/library/functions.html
3.自定义函数:
def function(arg1,arg2):
return 'something'
#def与return是python的关键字;function是函数的名字;arg1、arg2是函数所需的参数;return是函数输出的处理结果;注意冒号不要忘记。
示例:
def tixing(a,b,h):
s=(a+b)*h/2
return s
print('梯形的面积是:',str(tixing(1,2,3)))
2.python自带函数的介绍参见网址:https://docs.python.org/3/library/functions.html
3.自定义函数:
def function(arg1,arg2):
return 'something'
#def与return是python的关键字;function是函数的名字;arg1、arg2是函数所需的参数;return是函数输出的处理结果;注意冒号不要忘记。
示例:
def tixing(a,b,h):
s=(a+b)*h/2
return s
print('梯形的面积是:',str(tixing(1,2,3)))
def tixing(a,b,h):
s=(a+b)*h/2
print('梯形的面积是:',str(s))
b=tixing(1,2,3)# 输出梯形的面积是: 4.5
print(b) #输出None
#python定义函数时,return可以没有,是可选的(optional);只是返回值是None。
s=(a+b)*h/2
print('梯形的面积是:',str(s))
b=tixing(1,2,3)# 输出梯形的面积是: 4.5
print(b) #输出None
#python定义函数时,return可以没有,是可选的(optional);只是返回值是None。
def g2kg(g):
return g/1000
print(g2kg(1000)) #输出1.0
return g/1000
print(g2kg(1000)) #输出1.0
import math
def c(a,b):
return math.sqrt(a*a+b*b)
print(c(3,4))# 输出5.0
def c(a,b):
return math.sqrt(a*a+b*b)
print(c(3,4))# 输出5.0
def c(a,b):
return 'the third slide is {}'.format(str(((a**2+b**2)**(1/2))))
print(c(3,4))#输出the third slide is 5.0
return 'the third slide is {}'.format(str(((a**2+b**2)**(1/2))))
print(c(3,4))#输出the third slide is 5.0