
python基础
Li--AiTao
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python绘制sigmoid及tanh函数
Sigmoid激活函数 import math import numpy as np import matplotlib.pyplot as plt x = np.arange(-10,10) a=np.array(x) y1=1/(1+math.e**(-x)) y2=math.e**(-x)/((1+math.e**(-x))**2) plt.xlim(-11,11) ax = pl...原创 2019-12-04 10:21:28 · 2717 阅读 · 0 评论 -
python小程序,批量文件的替换
实现多个字符串的批量转换 import re import os s = os.sep root = "G:\daizhuan" for i in os.listdir(root): if os.path.isfile(os.path.join(root,i)): print ("i") filePath = os.path.join(...原创 2018-05-19 21:26:51 · 345 阅读 · 0 评论 -
python小程序,文本过滤器,过滤替换文本中的敏感词汇
def text_create(name,msg): desktop_path='C://Users/Allen/Desktop/' full_path=desktop_path+name+'.txt' file = open(full_path,'w') file.write(msg) file.close() print('Done') t...原创 2018-11-12 16:05:45 · 1370 阅读 · 0 评论 -
python学习,爬去豆瓣出版社
import urllib.request url=urllib.request.urlopen("https://read.douban.com/provider/all").read() url=url.decode("utf-8") import re pat='<div class="name">(.*?)</div>' data=re.compile(pat)...原创 2018-11-29 16:53:34 · 178 阅读 · 0 评论 -
python学习,新浪新闻的爬取和优快云博文爬取
import urllib.request import ssl import re#导入正则表达式模块 data=urllib.request.urlopen("http://news.sina.com.cn/").read()#将网址信息读取出来,并赋值给data #headers=("","")#此处可以添加模拟http请求,详见前面博文 #opener... #opener data2=...原创 2018-12-04 10:16:34 · 364 阅读 · 0 评论 -
python学习,代理服务器的使用
import urllib.request def use_proxy(url,proxy_addr): proxy=urllib.request.ProxyHandler({"http":proxy_addr})#使用代理服务器 opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)#给opene...原创 2018-12-04 15:31:42 · 864 阅读 · 0 评论 -
python学习,模拟post请求
import urllib.request import urllib.parse url="http://www.iqianyue.com/mypost/" data=urllib.parse.urlencode({ "name":"allen", "pass":"123" }).encode("utf-8") req=urllib.request.Request(ur原创 2018-12-03 10:10:36 · 880 阅读 · 0 评论 -
python学习,爬某宝图片
import urllib.request import re keyname="短裙" key=urllib.request.quote(keyname)#编码 headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0...原创 2018-12-05 15:19:45 · 226 阅读 · 1 评论 -
python学习,浏览器伪装
import urllib.request url="https://blog.youkuaiyun.com/VABTC" header=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.53 Safari/537.36") open...原创 2018-12-03 14:50:58 · 233 阅读 · 0 评论 -
python:高准确度中文分词工具,简单易用,跟现有开源工具相比大幅提高了分词的准确率。
工具地址,https://github.com/lancopku/PKUSeg-python原创 2020-08-01 09:49:04 · 239 阅读 · 0 评论 -
python基础,try错误调试
try: print('try...') r = 10 / int('a') print('result:',r) except ValueError as e: print('ValueError:',e) except ZeroDivisionError as e: print('ZeroDivisionError:',e) finally: p...原创 2018-04-17 09:01:17 · 333 阅读 · 0 评论 -
python小程序,统计学生个数
class Student(object): count = 0 def __init__(self,name): self.name = name Student.count +=1 if Student.count != 0: print('测试失败!') else: bart = Student('Bart') if Student.count != 1:...原创 2018-04-04 11:13:26 · 2729 阅读 · 0 评论 -
python小程序,编写一个函数,接受list并用reduce求积
from functools import reduce def prod(L): return reduce(lambda x,y:x * y,L) print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9])) if prod([3, 5, 7, 9]) == 945: print('测试成功!') else: print('测试失败!')原创 2017-12-27 21:09:06 · 1394 阅读 · 0 评论 -
python小程序,规范用户输入英文名的大小写(首字母大写)
def normalize(name): n = name.upper() if len(n) > 1: n = n[0] + n[1:].lower() return n L1 = ['fgdfg', 'WER', 'DFcf'] L2 = list(map(normalize, L1)) print(L2)原创 2017-12-27 20:39:13 · 4339 阅读 · 0 评论 -
python小程序,杨辉三角
def triangles(): L=[1] while True: L=[L[i]+[i+1] for i in range(len[L]-1)] L.insert(0,1) L.append(1)原创 2017-12-20 21:23:18 · 567 阅读 · 0 评论 -
python小程序,斐波拉契数列(Fibonacci)
列表生成式法:def fib(max): n, a, b = 0, 0, 1 while n < max: print(b) a, b = b, a + b n = n + 1 return 'done'生成器:generator法def fib(max): n, a, b = 0, 0, 1 while...原创 2017-12-20 20:24:21 · 583 阅读 · 0 评论 -
python基础,将str类型转换为float类型
from functools import reduce def str2float(s): L=s.split('.'); return reduce(lambda x,y:y+x*10,map(int,L[0]))+reduce(lambda x,y:y+x*10,map(int,L[1]))/10**len(L[1]) 方法2: from functools i原创 2018-01-23 10:32:32 · 11943 阅读 · 0 评论 -
python小程序,过滤偶数、空格、素数
过滤奇数:def odd(n): return n % 2 == 1 list(filter(is_odd, [1, 2, 3,4,5,6,7,8]))此处将filter换成map,可以看出map和filter的区别过滤空格:def not_empty(s): return s and s.strip() list(filter(not_empty, ['A', '', 'B'...原创 2018-01-25 11:14:01 · 604 阅读 · 0 评论 -
python基础,计数器函数(闭包的使用)
def createCounter(): def counter(): return next(o) def f(): i=0 while 1: i=i+1 yield i o=f() return counter原创 2018-03-22 21:48:00 · 2098 阅读 · 0 评论 -
python 小程序,按照姓名或成绩排序(sorted用法)
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)] def by_name(t): return t[0] L2 = sorted(L, key=by_name) print(L2)L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)] def by_score...原创 2018-03-21 11:07:13 · 13885 阅读 · 1 评论 -
python基础,@property装饰器求矩形面积
class Screen(object): @property def width(self): return self._width @width.setter def width(self,value): self._width = value @property def height(self): return height._width @height.sette...原创 2018-04-09 10:37:22 · 415 阅读 · 0 评论 -
python小程序,枚举12个月份
from enum import Enum >>> Month = Enum('Month', ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) >>> for name,member in Month.__members__.items()...原创 2018-04-11 10:58:35 · 1063 阅读 · 0 评论 -
python小程序,将str转换为int型,将int型转换为str型
将str型转换为int型from functools import reduce >>> def fn(x, y): ... return x * 10 + y ... >>> def char2num(s): ... digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6...原创 2018-01-22 11:01:30 · 5557 阅读 · 0 评论