摘要: day16 装饰器带参数: import time def timer(func): def func1(count): # 增加参数 time1 = time.time() func(count) # 传入参数 time2 = time.time() print('共使用了%s' % str(ti 阅读全文
posted @ 2019-12-23 23:39 绝世老中医 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 装饰器 给不同的函数增加通用的功能 闭包:函数对象+函数内部需要使用的外部变量=函数返回的整体 装饰器可以传入一个函数,返回一个函数对象 没有括号的叫函数对象 有括号的叫函数调用 def prc(): return sum >>> def func1(func): # func 是函数,函数,函数 阅读全文
posted @ 2019-12-23 23:38 绝世老中医 阅读(86) 评论(0) 推荐(0) 编辑
摘要: data = [] for i in range(1,5): for k in range(1,5): for m in range(1,5): if i != k and i != m and k != m: d = [] d.append(i) d.append(k) d.append(m) d 阅读全文
posted @ 2019-12-23 23:36 绝世老中医 阅读(202) 评论(0) 推荐(0) 编辑
摘要: day13 1.使用 while,计算随机数之和,超过 100 的时候,停 止程序。随机数 1-20 的范围产生,要求记录一下产生的随 机数,以及最后的和,以及随机数的个数 >>> import random >>> count = 0 >>> num = [] >>> num_add = 0 >> 阅读全文
posted @ 2019-12-23 10:01 绝世老中医 阅读(200) 评论(0) 推荐(0) 编辑
摘要: day12 1. 练习题第八题,将数字的每一位都+2,转换成一个新数字(整数和小数) def number(s): “”“如果不是int或者float类型就提示输入数字,就剔除了字母的情况,包括多个.等异常情况”“” new_s = [] if isinstance(s,float): # 如果是f 阅读全文
posted @ 2019-12-23 09:45 绝世老中医 阅读(295) 评论(0) 推荐(0) 编辑
摘要: day11 8.28 小练习 1 统计输入的字符多少个 >>> strs = str(input('pelase input str')) pelase input strtiyiyubhnljikmltuyohij;451515 >>> num = 0 >>> for i in strs: ... 阅读全文
posted @ 2019-12-23 09:40 绝世老中医 阅读(203) 评论(0) 推荐(0) 编辑
摘要: day10 1.输入 5 个名字,排序后输出 names = '' for i in range(5): name = input("please input the five name sep by , :") name = name + ',' names += name name_list = 阅读全文
posted @ 2019-12-23 09:38 绝世老中医 阅读(183) 评论(0) 推荐(0) 编辑
摘要: day9 1. >>> str_li = [] >>> while True: ... get_str = str(input(">>")) ... if get_str == 'end': ... break ... print(get_str) ... str_li.append(copy.de 阅读全文
posted @ 2019-12-23 09:35 绝世老中医 阅读(299) 评论(0) 推荐(0) 编辑
摘要: day8 1.10进制转化为2进制 10进制转化2进制主要采用反向取余法,用10进制除以2会得到商和余,再用商除2再得到商和余,一次类推,知道商为0时,然后从下往上取每次结果的余 def dev(s): result = [] while True: result.append(str(s/%)) 阅读全文
posted @ 2019-12-23 09:33 绝世老中医 阅读(253) 评论(0) 推荐(0) 编辑
摘要: day7 1.把字符串中的所有数字去掉 s = "a1b2c3b4d5dddddd" def move_num(s): result = '' for i in s: if i not in '1234567890': result += i return result 方法2:print(''.j 阅读全文
posted @ 2019-12-23 08:18 绝世老中医 阅读(308) 评论(0) 推荐(0) 编辑
摘要: day6 1.判断下标为是否为偶数的方式来实现,如果为耦合下标就把值累加 方法1 a = [1,2,1,2,3,3,3,3] result = 0 for i in a[::2]: result += i 方法2: for i in range(len(a)): if i%2 == 0: resul 阅读全文
posted @ 2019-12-23 08:15 绝世老中医 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 1.求全部元素的和 [1,2,1,2,3,3,3,3] 遍历 a = [1,2,1,2,3,3,3,3] sum = 0 n = len(a)-1 while n>=0: sum += a[n] n -= 1 2.求偶数元素的和 [1,2,1,2,3,3,3,3] a = [1,2,1,2,3,3, 阅读全文
posted @ 2019-12-23 08:13 绝世老中医 阅读(215) 评论(0) 推荐(0) 编辑
摘要: day5: 序列,可以使用切片 序列类型:字符串,列表,元祖 特点:可以通过坐标来取值,坐标从0开始 >>> s = "agfdagsgsdgsa" >>> print(s[0]) a >>> print(s[1]) g >>> s = [1,2,3,4,5,6] >>> print(s[1]) 2 阅读全文
posted @ 2019-12-23 08:12 绝世老中医 阅读(229) 评论(0) 推荐(0) 编辑
摘要: day3复习 >>> for i in range(10): ... if i == 3: ... break ... print(i) ... 0 1 2 >>> for i in range(10): ... if i == 3: ... continue ... print(i) ... 0 阅读全文
posted @ 2019-12-23 08:11 绝世老中医 阅读(306) 评论(0) 推荐(0) 编辑
摘要: >>> def str_len(s): ... l = len(s) ... if l > 3: ... print("3") ... elif l < 3: ... print("2") ... elif l == 3: ... print("1") ... else: ... print("0" 阅读全文
posted @ 2019-12-23 08:09 绝世老中医 阅读(298) 评论(0) 推荐(0) 编辑
摘要: >>> a = '123' >>> isinstance(a, str) True >>> b = 1 >>> type(b) <class 'int'> >>> isinstance(b, int) True >>> c = [1,2,3,4] >>> type(c) <class 'list'> 阅读全文
posted @ 2019-12-23 08:07 绝世老中医 阅读(250) 评论(0) 推荐(0) 编辑