Study python_03

函数

基本思想---函数是用来重复使用的

def shili(input_):
    print("我了个去 %s"%input_)
shili('你竟然')

 

当一个函数中即有默认参数,

又有变量参数时,

需要将默认参数放在最后面

def shili(a, b = 1):
    print(a,b)
shili(99)

 

      简单使用函数

        1/3+3/5+5/7+...+n/n+2

def xx(res):
    for i in range(1,98,2):
        res +=  i/ (i+2)
    print(res)
xx(0)

 

简单的匹配手机号

  使用正则表达式

import re
compile_ =re.compile('^1[3456789]\d{9}')# 正则表达式
res = compile_.findall('15088888888')
print(res)# 成功输出手机号,不成功输出空

 

简单的倒数读秒

import time
for  seconds  in range(10,0,-1):
    time.sleep(1)
    print('%d秒'%seconds)
posted @ 2019-08-01 20:57  千纪  阅读(107)  评论(0编辑  收藏  举报