随笔分类 -  小练习

python绘图练习
摘要:1 turtle绘制奥运五环图 import turtle as p def drawCircle(x,y,c='red'): p.pu()# 抬起画笔 p.goto(x,y) # 绘制圆的起始位置 p.pd()# 放下画笔 p.color(c)# 绘制c色圆环 p.circle(30,360) # 阅读全文

posted @ 2020-04-01 20:00 不要挡着我晒太阳 阅读(821) 评论(0) 推荐(0) 编辑

小练习2
摘要:1#测试函数执行时间的装饰器示例 import time def timing_func(fn): def wrapper(): start=time.time() fn() #执行传入的fn参数 stop=time.time() return (stop-start) return wrapper 阅读全文

posted @ 2020-04-01 16:48 不要挡着我晒太阳 阅读(167) 评论(0) 推荐(0) 编辑

小练习
摘要:1 寻找第n次出现位置 def search_n(s, c, n): size = 0 for i, x in enumerate(s): if x == c: size += 1 if size == n: return i return -1 print(search_n("fdasadfadf 阅读全文

posted @ 2020-04-01 15:44 不要挡着我晒太阳 阅读(174) 评论(0) 推荐(0) 编辑

4G 内存处理 10G 大小的文件
摘要:4G 内存处理 10G 大小的文件,单机怎么做? 下面的讨论基于的假定:可以单独处理一行数据,行间数据相关性为零。 方法一: 仅使用 Python 内置模板,逐行读取到内存。 使用 yield,好处是解耦读取操作和处理操作: def python_read(filename): with open( 阅读全文

posted @ 2020-04-01 14:19 不要挡着我晒太阳 阅读(907) 评论(1) 推荐(0) 编辑

线程模块练习
摘要:1.主线程 import threading t = threading.current_thread() print(t) # <_MainThread(MainThread, started 139908235814720)> print(t.getName()) # MainThread pr 阅读全文

posted @ 2020-04-01 14:07 不要挡着我晒太阳 阅读(110) 评论(0) 推荐(0) 编辑

时间模块练习
摘要:1.年的日历图 import calendar from datetime import date mydate = date.today() year_calendar_str = calendar.calendar(2019) print(f"{mydate.year}年的日历图:{year_c 阅读全文

posted @ 2020-04-01 13:32 不要挡着我晒太阳 阅读(138) 评论(0) 推荐(0) 编辑

python文件操作练习
摘要:1.获取后缀名 import os file_ext = os.path.splittext('./data/py/test.py') front,ext = file_ext print(front,ext) #'./data/py/test' #'.py' 2.创建文件夹 def mkdir(p 阅读全文

posted @ 2020-03-31 19:17 不要挡着我晒太阳 阅读(401) 评论(0) 推荐(0) 编辑

判断str1是否由str2旋转而来
摘要:stringbook旋转后得到bookstring,写一段代码验证str1是否为str2旋转得到。 思路 转化为判断:str1是否为str2+str2的子串(因为该思路比较巧妙,故记录下来) def is_rotation(s1: str, s2: str) -> bool: if s1 is No 阅读全文

posted @ 2020-03-31 16:40 不要挡着我晒太阳 阅读(188) 评论(0) 推荐(0) 编辑

字符串切片操作——查找替换3或5的倍数
摘要:[str("java"[i%3*4:]+"python"[i%5*6:] or i) for i in range(1,15)] 阅读全文

posted @ 2020-03-31 14:06 不要挡着我晒太阳 阅读(254) 评论(0) 推荐(0) 编辑

待填坑
摘要:今天看见一个烧脑的代码,一时没看懂结果,刨个坑,看懂填 def product(*args, repeat=1): pools = [tuple(pool) for pool in args] * repeat result = [[]] for pool in pools: result = [x 阅读全文

posted @ 2020-03-31 13:28 不要挡着我晒太阳 阅读(124) 评论(0) 推荐(0) 编辑

小练手3
摘要:1.""" # Write a program to compute:## f(n)=f(n-1)+100 when n>0# and f(0)=1## with a given n input by console (n>0).## Example:# If the following n is 阅读全文

posted @ 2019-12-13 17:52 不要挡着我晒太阳 阅读(151) 评论(0) 推荐(0) 编辑

小练手2
摘要:1. """ Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters. Suppose the following input is s 阅读全文

posted @ 2019-12-13 17:43 不要挡着我晒太阳 阅读(286) 评论(0) 推荐(0) 编辑

python小练手题1
摘要:1. """ Write a program which can compute the factorial of a given numbers. The results should be printed in a comma-separated sequence on a single lin 阅读全文

posted @ 2019-12-13 16:41 不要挡着我晒太阳 阅读(446) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示