################################################################################################################
#高阶函数的定义:
#1.函数接收的参数是一个函数名
#2.函数的返回值是一个函数名
#3.满足上述条件的任意一个都可以称为高阶函数
## import time
# def foo():
# time.sleep(3)
# print('你好啊林师傅')
#
# def test(func):
# # print(func)
# start_time=time.time()
# func()
# stop_time = time.time()
# print('函数运行时间是 %s' % (stop_time-start_time))
# # foo()
# test(foo)
###############################################################################################################
# def foo():
# print('from the foo')
# def test(func):
# return func # res=test(foo)
# # print(res)
# res() # foo=test(foo)
# # # print(res)
# foo()
# import time
# def foo():
# time.sleep(3)
# print('来自foo')
#不修改foo源代码
#不修改foo调用方式
##############################################################################################################
#多运行了一次,不合格
# def timer(func):
# start_time=time.time()
# func()
# stop_time = time.time()
# print('函数运行时间是 %s' % (stop_time-start_time))
# return func
# foo=timer(foo)
# foo()
#没有修改被修饰函数的源代码,也没有修改被修饰函数的调用方式,但是也没有为被修饰函数添加新功能
# def timer(func):
# start_time=time.time()
# return func
# stop_time = time.time()
# print('函数运行时间是 %s' % (stop_time-start_time))
#
# foo=timer(foo)
# foo()
##################################################################################################################
#函数的嵌套:在函数内部重新定义新的函数称为函数的嵌套,在函数内部调用其他函数不是函数的嵌套
# def bar():
# print('from bar')
# def foo():
# print('from foo')
# bar()
# pass
# print(foo())
#######################
# def father(name):
# print('from father %s'%name)
# def son():
# print('from son')
# def grandson():
# print('from grandson')
# grandson()
# son()
# father('pandaboy')
# from father pandaboy
# from son
# from grandson
#闭包:在当前函数内找到的自己包中的变量,找不到的变量去外部找,函数作用域的体现
###################################################################################################################
#装饰器的实现:
# 1.定义一个函数(参数为另一个函数)
# 2.设定返回值,返回值为内部函数名称
# 3.定义内部函数,设定内部函数的方法
#####################################################################################################################
#装饰器的框架:
# def timer(func):
# def wrapper():
# # print(func)#嵌套的作用域
# strat_time = time.time()
# func()
# stop_time = time.time()
# print('运行时间是%s'%(stop_time-strat_time))
# return wrapper
####################################################################################################################
# import time
# @timer#作用是对函数进行计时
# def test():
# time.sleep(3)
# print('test函数运行完毕')
# timer(test)#返回的是wrapper的地址
# test = timer(test)
# test()
# test函数运行完毕
# 运行时间是3.0108001232147217
########################################加上返回值#####################################################
# def timer(func):
# def wrapper():
# # print(func)#嵌套的作用域
# strat_time = time.time()
# res = func()#赋值给func(),实际会赋值给test函数的一个返回值
# stop_time = time.time()
# print('运行时间是%s'%(stop_time-strat_time))
# return res#设定返回值
# return wrapper
# import time
# @timer#作用是对函数进行计时
# def test():
# time.sleep(3)
# print('test函数运行完毕')
# return 1
# # timer(test)#返回的是wrapper的地址
# # test = timer(test)
# res1 = test()
# print(res1)
#########################################加上参数######################################################
# def timer(func):
# def wrapper(*args,**kwargs):#默认可以输入任何参数
# # print(func)#嵌套的作用域
# strat_time = time.time()
# res = func(*args,**kwargs)#就是在运行test(),赋值给func(),实际会赋值给test函数的一个返回值
# stop_time = time.time()
# print('运行时间是%s'%(stop_time-strat_time))
# return res#设定返回值
# return wrapper
# import time
# @timer#test = timer(test)作用是对函数进行计时
# def test(name,age):
# time.sleep(3)
# print('test函数运行完毕,【名字是】:%s,【年龄是】:%s'%(name,age))
# return 1
# # timer(test)#返回的是wrapper的地址
# # test = timer(test)
# res1 = test('alex','18')#就是在运行wrapper
# print(res1)
#################################################################################################################
#解压序列 a,b,c = (1,2,3)数值是一一对应的关系
#交换解压序列
# a,b = (1,2)
# a,b = b,a
# print(a,b)
# 2 1
# user_dic = {'username':None,'login':False}
#
# def auth_func(func):
# def wrapper(*args,**kwargs):
# if user_dic['username'] and user_dic['login'] == True:
# res = func(*args, **kwargs)
# return res
# username = input('用户名:').strip()
# password = input('密码:').strip()
# if username =='pandaboy' and password =='123456':
# user_dic['username'] = username
# user_dic['login'] = True
# res = func(*args,**kwargs)
# return res
# else:
# print('用户名或密码错误')
# return wrapper
# @auth_func
# def index():
# print('欢迎来到主页')
# @auth_func
# def home(name):
# print('欢迎访问根目录%s'%name)
# def shopping_car():
# print('查询数据库里的内容')#需要访问列表中的数据库数据
# def order():
# print('查询订单内容')
# #给所有的函数加上验证功能
# index()
# home('alex')
###################################根据列表内容查询用户名及密码(不写死)####################################################
# user_list=[
# {'name':'alex','passwd':'123'},
# {'name':'linhaifeng','passwd':'123'},
# {'name':'wupeiqi','passwd':'123'},
# {'name':'yuanhao','passwd':'123'},
# ]
# current_dic = {'username':None,'login':False}
# def auth_func(func):
# def wrapper(*args,**kwargs):
# if current_dic['username'] and current_dic['login'] == True:
# res = func(*args, **kwargs)
# return res
# username = input('用户名:').strip()
# password = input('密码:').strip()
# for user_dic in user_list:
# if username ==user_dic['name'] and password ==user_dic['passwd']:
# current_dic['username']=username
# current_dic['login']=True
# res = func(*args, **kwargs)
# return res
# else:
# print('用户名或密码错误')
# return wrapper
# @auth_func
# def index():
# print('欢迎来到主页')
# @auth_func
# def home(name):
# print('欢迎访问根目录%s'%name)
# def shopping_car():
# print('查询数据库里的内容')#需要访问列表中的数据库数据
# def order():
# print('查询订单内容')
# #给所有的函数加上验证功能
# index()
# home('alex')
# # 用户名:alex
# # 密码:123
# # 欢迎来到主页
# # 欢迎访问根目录alex
##################################################################################################################
# 关系型数据库:Mysql Oracle
#集中账号管理ldap

Pyhton学习——Day10的更多相关文章

  1. day10 Pyhton学习

    一.昨日内容回顾 函数: 定义:对功能或者动作的封装 def 函数名(形参): 函数体 函数名(实参) return:  返回,当程序运行到return的时候,终止函数的执行 一个函数一定拥有返回值 ...

  2. python开发学习-day10(select/poll/epoll回顾、redis、rabbitmq-pika)

    s12-20160319-day10 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  3. Pyhton学习——Day26

    #多态:多态指的是一类事物有多种形态# import abc# class Animal(metaclass = abc.ABCMeta):# 同一类事物:动物# @abc.abstractclass ...

  4. pyhton 学习

    官方学习文档 https://docs.python.org/3/tutorial/

  5. 20190320_head first pyhton学习笔记之构建发布

    1.把代码nester.py放入文件夹nester中,在文件夹中再新建一个setup.py文件,文件内容如下: from distutils.core import setup setup( name ...

  6. python学习Day10 函数的介绍(定义、组成、使用)

    今日学习内容: 1.什么是函数 :函数就是一个含有特定功能的变量,一个解决某问题的工具 函数的定义:通过关键字def + 功能名字():代码体(根据需求撰写代码逻辑) 2.为什么要用函数:可以复用:函 ...

  7. Python学习 day10

    一.默认参数的陷阱 先看如下例子: def func(li=[]): li.append(1) print(li) func() func() func(li=['abc']) func() 结果: ...

  8. Python学习-day10 进程

    学习完线程,学习进程 进程和线程的语法有很多一样的地方,不过在操作系统中的差别确实很大. 模块是threading 和 multiprocessing 多进程multiprocessing multi ...

  9. 算法学习--Day10

    今天开始了新一章的学习,前面的题目虽然做了几道,但是我觉得训练量仍然太小了.不过机试确实很多题目,并且难度也有所不同,所以要针对不同的题目进行专门的练习才好.题目类型有些多,等接下来我将搜索的题目写完 ...

随机推荐

  1. pip是用代理

    内网访问外网时,需要通过vpn访问,但是pip貌似不能是用vpn访问外网.直接度娘: windows下: set http_proxy=http://代理服务器:端口 不行可以试试下面的: set h ...

  2. selenium的显示等待和隐式等待区别

    1.selenium的显示等待 原理:显式等待,就是明确的要等到某个元素的出现或者是某个元素的可点击等条件,等不到,就一直等,除非在规定的时间之内都没找到,那么就跳出Exception.(简而言之:就 ...

  3. javaScript原型、闭包和异步操作

    同学们,这篇博客有点水了,并不是说我不想写这块的内容,是因为查了很多资料,看了很多帖子之后,发现园内王福朋老师写的这系列文章真的很好,他的这系列的博客我已经看了3.4遍了,每一次都有新的收获,我可写不 ...

  4. [luogu4151 WC2011] 最大XOR和路径 (线性基)

    传送门 输入输出样例 输入样例#1: 5 7 1 2 2 1 3 2 2 4 1 2 5 1 4 5 3 5 3 4 4 3 2 输出样例#1: 6 说明 [样例说明] 根据异或的性质,将一个数异或两 ...

  5. 深入理解B/S与C/S架构

    首先来介绍一下B/S与C/S架构 C/S架构简要介绍 在了解什么是B/S架构之前,我们有必要了解一下什么是C/S架构: C/S架构是第一种比较早的软件架构,主要用于局域网内.也叫 客户机/服务器模式. ...

  6. C/C++ 文件路径解析

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50782054 首先,看一下C/C++中 ...

  7. BIRT报表Cannot open the connection for the driver:org.eclipse.birt.report.data.oda.jdbc.dbprofile

    现象:报表不能打开: 找了半个小时,随手改了一下tomcat/conf文件夹下的context.xml文件 <Context xmlBlockExternal="false" ...

  8. 工具-vscode使用

    1.智能感知 vscode使用DefinitelyTyped进行自动完成所以需要先安装tsd,命令: npm install -g tsd 安装完成后,首先安装node基本语法支持 tsd query ...

  9. POJ 1091

    这题确实是好. 其实是求x1*a1+x2*a2+....M*xn+1=1有解的条件.很明显,就是(a1,a2,...M)=1了.然后,可以想象,直接求有多少种,很难,所以,求出选择哪些数一起会不与M互 ...

  10. Java Secret: Using an enum to build a State machine(Java秘术:用枚举构建一个状态机)

    近期在读Hadoop#Yarn部分的源代码.读到状态机那一部分的时候,感到enmu的使用方法实在是太灵活了,在给并发编程网翻译一篇文章的时候,正好碰到一篇这种文章.就赶紧翻译下来,涨涨姿势. 原文链接 ...