摘要: 一、列表 1、count() 定义:统计指定元素在列表中出现的次数并返回这个数。若指定的元素不存在则返回:0。 格式:[列表].count(“指定元素”) 例:统计指定元素的个数 l = ['xiaobai','lisa','Miss_Jing','yujiemeigui','taidi'] l1 阅读全文
posted @ 2017-06-25 14:50 御姐玫瑰 阅读(1035) 评论(0) 推荐(0) 编辑
摘要: Python字符串方法图示: (温馨提示:对图片点右键——在新标签页中打开图片) 1、index() 定义:查找并返回指定str的索引位置,如果没找到则会抛异常(查找的顺序是从左至右)可以指定范围:开始位置和结束位置进行查找。 格式:“字符串内容”.index('指定的字符串',指定范围) 例1:不 阅读全文
posted @ 2017-06-23 15:57 御姐玫瑰 阅读(1000) 评论(1) 推荐(2) 编辑
摘要: 示例代码 def decorator(fn): def inner(*args, **kwargs): print("正在进行装饰") ret = fn(*args, **kwargs) # 调用play_game()函数 return ret # 返回inner函数的返回值 return inne 阅读全文
posted @ 2021-04-02 19:06 御姐玫瑰 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 示例代码: import time def cal_time(fn): """计算程序运行时间的函数""" def inner(x, *args, **kwargs): start_time = time.time() print(args) # 元组解包,('lisa',) print(kwarg 阅读全文
posted @ 2021-04-02 19:04 御姐玫瑰 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 示例代码: import time def cal_time(fn): def inner(num): start_time = time.time() ret = fn(num) # 调用原有函数,将num传递给fn end_time = time.time() print("程序一共运行了%s" 阅读全文
posted @ 2021-04-02 19:00 御姐玫瑰 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 示例代码 import time def cal_time(fn): """计算程序运行时间的函数""" def inner(): start_time = time.time() ret = fn() end_time = time.time() print("程序一共执行了%s" % (end_ 阅读全文
posted @ 2021-04-02 18:57 御姐玫瑰 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 示例代码: import time def cal_time(fn): def inner(): start_time = time.time() fn() # 调用原始函数 end_time = time.time() print("程序一共执行了%s" %(end_time - start_ti 阅读全文
posted @ 2021-04-02 18:56 御姐玫瑰 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 示例代码 import time def run_time(func): """计算程序运行时间的函数""" start_time = time.time() func() end_time = time.time() print("程序一共执行了%s" % (end_time - start_ti 阅读全文
posted @ 2021-04-02 18:53 御姐玫瑰 阅读(63) 评论(0) 推荐(0) 编辑
摘要: 描述: 要求: 计算阶乘的计算时间 什么是时间戳? 从1970年1月1日00:00时的UTC时间到现在的秒数。 UTC时间:协调世界时,又称世界统一时间、世界标准时间、国际协调时间 示例代码: import time start_time = time.time() # time.time()——获 阅读全文
posted @ 2021-04-02 18:52 御姐玫瑰 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 描述 nonlocal 关键字可以用来修改局部变量 nonloca l只在闭包里面生效,作用域就是闭包里面的,外函数和内函数都影响,但是闭包外面不影响。 示例代码: x = 100 def outer(): x = 10 print("外部函数的变量x的值是:%s" % x) def inner() 阅读全文
posted @ 2021-04-02 18:49 御姐玫瑰 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 描述 闭包的定义: 两个函数嵌套,外部的函数需要返回内部函数的引用 内部函数使用了外部函数的局部变量示例代码: def outer(): x = 100 # 局部变量 def inner(): return x + 1 return inner # 外部函数返回内部函数的引用 z = outer() 阅读全文
posted @ 2021-04-02 18:39 御姐玫瑰 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 描述: 高阶函数的三种方式: (1)一个函数作为另一个函数的返回值 (2)一个函数作为另一个函数的参数 (3)函数内部再定义一个函数 示例代码1:一个函数作为另一个函数的返回值 def foo(): print('foo函数') return 'foo' def bar(): print('bar函 阅读全文
posted @ 2021-04-02 18:35 御姐玫瑰 阅读(77) 评论(0) 推荐(0) 编辑
levels of contents