Giter Club home page Giter Club logo

python-small-examples's Introduction




介绍

告别枯燥,告别枯燥,致力于打造 Python 经典小例子、小案例。 如果转载本库小例子、小案例,请备注下方链接:Python小例子 https://github.com/jackzhenguo/python-small-examples

查看完整的旧版本:改版前V3.0

贡献

欢迎贡献小例子到此库

License

允许按照要求转载,但禁止用于任何商用目的。

Python 原创教程

这是经过很久打磨的一个Python教程,全部是个人原创,已首发在公众号,并且托管在我的个人网站。想系统入门Python的欢迎学习:

Python教程

后续章节正在整理推送中。

Python 小例子

编号 链接 标签 版本 难度
1 实现 relu max V4.0 ⭐️⭐️
2 进制转化 bin,oct,hex V4.0 ⭐️⭐️
3 整数和ASCII互转 chr,ord V1.0 ⭐️⭐️
4 元素都为真检查 all V2.0 ⭐️⭐️⭐️
5 至少一个为真检查 any V2.0 ⭐️⭐️⭐️
6 判断是真是假 bool V2.0 ⭐️⭐️⭐️
7 创建复数 complex V1.0 ⭐️⭐️⭐️
8 取商和余数 divmod V1.0 ⭐️⭐️
9 转为浮点类型 float V1.0 ⭐️⭐️
10 转为整型 int V1.0 ⭐️
11 次幂 pow V1.0 ⭐️
12 四舍五入 round V1.0 ⭐️
13 链式比较 compare V1.0 ⭐️⭐️
14 字符串转字节 bytes,utf-8 V1.0 ⭐️⭐️
15 任意对象转为字符串 str V1.0 ⭐️⭐️
16 执行字符串表示的代码 compile V1.0 ⭐️⭐️⭐️
17 计算表达式 eval V1.0 ⭐️⭐️⭐️⭐️
18 字符串格式化 format V1.0 ⭐️⭐️⭐️⭐️
19 拿来就用的排序函数 sorted V1.0 ⭐️⭐️⭐️
20 求和函数 sum V1.0 ⭐️⭐️
21 nonlocal用于内嵌函数中 nonlocal V2.0 ⭐️⭐️⭐️⭐️⭐️
22 global 声明全局变量 global V2.0 ⭐️⭐️⭐️⭐️⭐️
23 交换两元素 pack,unpack V1.0 ⭐️⭐️
24 操作函数对象 operator V2.0 ⭐️⭐️⭐️⭐️
25 生成逆序序列 range V1.0 ⭐️⭐️
26 函数的五类参数使用例子 variable parameter V2.0 ⭐️⭐️⭐️⭐️
27 使用slice对象 slice V2.0 ⭐️⭐️⭐️⭐️⭐️
28 lambda 函数 lambda V3.0 ⭐️⭐️⭐️⭐️
29 转为字典 dict V1.0 ⭐️⭐️
30 冻结集合 frozenset V1.0 ⭐️⭐️
31 转为集合类型 set V1.0 ⭐️⭐️
32 转元组 tuple V1.0 ⭐️⭐️
33 对象是否可调用 callable V2.5 ⭐️⭐️⭐️⭐️
34 ascii 展示对象 __repr__ V2.5 ⭐️⭐️⭐️
35 类方法 classmethod V1.5 ⭐️⭐️⭐️
36 动态删除属性 delattr,hasattr V1.5 ⭐️⭐️
37 一键查看对象所有方法 dir V1.5 ⭐️⭐️
38 动态获取对象属性 getattr V1.5 ⭐️⭐️
39 对象是否有某个属性 hasattr V1.5 ⭐️⭐️⭐️
40 对象门牌号 id V1.0 ⭐️
41 实例和对象关系判断 isinstance V1.5 ⭐️⭐️⭐️
42 issubclass父子关系鉴定 issubclass V1.5 ⭐️⭐️⭐️
43 所有对象之根 object V1.0 ⭐️
44 创建属性的两种方法 property V2.5 ⭐️⭐️⭐️⭐️⭐️
45 查看对象类型 type V1.0 ⭐️
46 元类使用介绍 type,__class__ V2.0 ⭐️⭐️⭐️⭐️⭐️
47 枚举对象 enumerate V1.0 ⭐️⭐️⭐️
48 查看变量所占字节数 getsizeof V1.0 ⭐️⭐️⭐️
49 过滤器filter filter V1.5 ⭐️⭐️⭐️
50 返回对象哈希值 hash V1.0 ⭐️⭐️
51 help 一键帮助 help V1.0 ⭐️
52 获取用户输入 input V1.0 ⭐️
53 创建迭代器 iter,__iter__ V1.5 ⭐️⭐️⭐️
54 文件读写和mode 取值表 open,read,write,with,mode V2.0 ⭐️⭐️⭐️
55 创建range序列 range V1.0 ⭐️⭐️
56 反向迭代器reversed reversed V1.0 ⭐️⭐️
57 zip迭代器 zip V1.5 ⭐️⭐️⭐️
58 operator使用举例 operator V1.0 ⭐️⭐️⭐️⭐️
59 传输json对象 json V2.0 ⭐️⭐️⭐️⭐️⭐️
60 不用else和if实现计算器 operator V1.0 ⭐️⭐️⭐️
61 去最求平均 list,sort,round V1.0 ⭐️⭐️⭐️⭐️
62 打印99乘法表 for,range,format V1.0 ⭐️⭐️⭐️
63 递归版flatten函数 recursion,list,isinstance V1.0 ⭐️⭐️⭐️⭐️
64 列表等分为n份 list,ceil V1.0 ⭐️⭐️⭐️
65 压缩列表 list,filter V1.0 ⭐️⭐️⭐️⭐️
66 求更长的列表 max,lambda V1.0 ⭐️⭐️⭐️⭐️⭐️
67 求列表众数 max,lambda,count V1.0 ⭐️⭐️⭐️⭐️
68 所有多个列表的最大值 max,lambda V1.0 ⭐️⭐️⭐️⭐️
69 列表检查重复 set V1.0 ⭐️⭐️⭐️
70 一行代码实现列表反转 reverse V1.0 ⭐️⭐️
71 浮点数等差数列 range,float V1.0 ⭐️⭐️⭐️⭐️
72 按条件分组 lambda V1.0 ⭐️⭐️⭐️⭐️
73 map实现向量运算 map,lambda V1.0 ⭐️⭐️⭐️
74 值最大的字典 max,lambda V1.0 ⭐️⭐️⭐️⭐️
75 合并两个字典 ** V1.0 ⭐️⭐️⭐️
76 Topn 字典 heapq,nlargest V1.0 ⭐️⭐️⭐️
77 判断是否为异位词 collections,Counter V1.0 ⭐️⭐️⭐️
78 逻辑上合并字典 ChainMap V1.0 ⭐️⭐️⭐️⭐️⭐️
79 带名字的元组 namedtuple V1.0 ⭐️⭐️⭐️
80 sample 样本抽样 random,sample V1.0 ⭐️⭐️⭐️
81 重洗数据集 shuffle V1.0 ⭐️⭐️⭐️
82 10个均匀分布的坐标点 random,uniform V1.0 ⭐️⭐️⭐️
83 10个高斯分布的坐标点 random,gauss V1.0 ⭐️⭐️⭐️⭐️
84 chain串联小容器为大容器 itertools,chain V1.0 ⭐️⭐️⭐️⭐️⭐️
85 product 使用案例 product V1.0 ⭐️⭐️⭐️⭐️⭐️
86 反转字符串的两个方法 reversed V1.0 ⭐️⭐️
87 join 串联字符串 join V1.0 ⭐️⭐️
88 字符串字节长度 encode V1.0 ⭐️⭐️
89 正则中字符 r作用 re,r V3.0 ⭐️⭐️⭐️
90 正则原子操作 re V3.0 ⭐️⭐️⭐️
91 正则中的转义 re,\ V3.0 ⭐️⭐️⭐️
92 正则最普通查找 re,findall V3.0 ⭐️⭐️⭐️
93 使用通用字符查找 re,\s,\w,\d V3.0 ⭐️⭐️⭐️
94 使用元字符查找 re,+,* V3.0 ⭐️⭐️⭐️
95 捕获子串 () V3.0 ⭐️⭐️⭐️⭐️
96 贪心捕获和非贪心捕获 re V1.0 ⭐️⭐️⭐️⭐️
97 使用正则做密码安全检查 re V1.0 ⭐️⭐️⭐️⭐️⭐️
98 爬取百度首页标题 re V1.0 ⭐️⭐️⭐️⭐️
99 批量转化为驼峰格式(Camel) re V1.0 ⭐️⭐️⭐️⭐️⭐️
100 是否互为排序词 collections,defaultdict V1.0 ⭐️⭐️⭐️⭐️
101 str1是否由str2旋转而来 str V1.0 ⭐️⭐️⭐️
102 使用正则判断是否为正浮点数 str,re,float V1.0 ⭐️⭐️⭐️⭐️⭐️
103 获取文件后缀名 os,splitext V1.0 ⭐️⭐️
104 获取路径中的文件名 os,split V1.0 ⭐️⭐️
105 批量修改文件后缀 argparse,listdir V1.0 ⭐️⭐️⭐️⭐️
106 xls批量转换成xlsx os,listdir,splitext V1.0 ⭐️⭐️⭐️⭐️
107 获取指定后缀名的文件 os,listdir,splitext V1.0 ⭐️⭐️⭐️⭐️
108 批量压缩文件 zipfile V1.0 ⭐️⭐️⭐️⭐️
109 32位加密 hashlib V1.0 ⭐️⭐️⭐️⭐️
110 年的日历图 calendar V1.0 ⭐️⭐️
111 判断是否为闰年 calendar V1.0 ⭐️⭐️⭐️
112 判断月有几天 calendar,datetime V1.0 ⭐️⭐️⭐️
113 月的第一天 datetime V1.0 ⭐️⭐️
114 月的最后一天 calendar,datetime V1.0 ⭐️⭐️
115 获取当前时间 time,datetime V1.0 ⭐️⭐️
116 字符时间转时间 time,datetime V1.0 ⭐️⭐️
117 时间转字符时间 time,datetime V1.0 ⭐️⭐️
118 默认启动主线程 threading V1.0 ⭐️⭐️
119 创建线程 threading V1.0 ⭐️⭐️
120 交替获得CPU时间片 threading V1.0 ⭐️⭐️⭐️
121 多线程抢夺同一个变量 threading V1.0 ⭐️⭐️⭐️
122 多线程变量竞争引起的问题 threading V1.0 ⭐️⭐️⭐️
123 多线程锁 threading,lock V1.0 ⭐️⭐️⭐️
124 时间转数组及常用格式 time,datetime,format V1.0 ⭐️⭐️⭐️
125 寻找第n次出现位置 enumerator V1.0 ⭐️⭐️⭐️
126 斐波那契数列前n项 yield,range V1.0 ⭐️⭐️⭐️
127 找出所有重复元素 calendar,datetime V1.0 ⭐️⭐️⭐️⭐️
128 联合统计次数 Counter V1.0 ⭐️⭐️⭐️⭐️⭐️
129 groupby单字段分组 itertools, groupby,lambda V1.0 ⭐️⭐️⭐️
130 groupby多字段分组 itemgetter,itertools,groupby V1.0 ⭐️⭐️⭐️⭐️
131 itemgetter和key函数 operator,itemgetter,itertools V1.0 ⭐️⭐️⭐️⭐️⭐️
132 sum函数计算和聚合同时做 sum,generator V1.0 ⭐️⭐️⭐️⭐️⭐️
133 获得某天后的1~n天 Calendar,monthrange V4.0 ⭐️⭐️⭐️
134 list分组(生成器版) yield,generator V1.0 ⭐️⭐️⭐️
135 列表全展开(生成器版) list,yield,generator V1.0 ⭐️⭐️⭐️
136 测试函数运行时间的装饰器 decorator V1.0 ⭐️⭐️⭐️⭐️
137 统计异常次数装饰器 decorator,nonlocal V1.5 ⭐️⭐️⭐️⭐️
138 通俗理解装饰器 decorator V1.0 ⭐️⭐️⭐️
139 定制递减迭代器 Iterator V3.0 ⭐️⭐️⭐️⭐️
140 turtle绘制奥运五环图 turtle V1.0 ⭐️⭐️⭐️
141 turtle绘制漫天雪花 turtle V1.0 ⭐️⭐️⭐️

更多例子正在整理发布中......

python-small-examples's People

Contributors

jackzhenguo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.