python format字符串格式化、数学意义的函数与python中的函数 day14

format字符串格式化,必须一一对应

tpl = 'i am {}, age{},{}'.format('seven',18,12)
print(tpl)
tpl = 'i am {1}, age{2},{2}'.format('seven',18,12)
print(tpl)

取元组第一个

tpl = ‘i am {0[0]}’,format([1,2,3],[123])

 

python 中函数定义方法:

def test(x):
    'The function definitions'#注释函数
    x+=1
    return x

 

def:定义函数的关键字

test:函数名

():内科定义形参

‘’文档描述,非必要,强烈建议添加

x+=1:泛指代码块或程序处理逻辑

return:定义返回值

使用函数

def test(x):
    ':param X:整形数字'#注释函数
    y=2*x+1
    return y
print(test)
a = test(3)
print(a)

没有返回值,返回None

只有一个返回值,返回该值

有多个返回值,返回元组

 

函数的参数

形参,只有调用函数时才有用

实参,一直存在

形参,实参一一对应

def text(x,y):
    res=x*y
    return res
z = text(1,2)
print(z)

参数组  **字典 *列表

def text(x,*y):
    print(x)
    print(y)
c= text(1,2,3,4,5)

 

posted @ 2018-06-29 23:55  血灵狂雷  阅读(150)  评论(0编辑  收藏  举报