随笔分类 -  Python

摘要:import jieba fp1=r'D:/python/a.txt' outph=r'D:/python/out.txt' f=open(fp1,'r',encoding='utf-8') txt=f.read().strip() f.close() words=jieba.lcut(txt) f=open(outph,'w',encoding='utf-8') for word in word 阅读全文
posted @ 2019-08-31 18:31 Andhui 阅读(3926) 评论(0) 推荐(0)
摘要:''' 练习一:编写名为collatz(number)的函数;实现的功能:参数为偶数时,打印number// 2;参数为奇数时,打印3*number + 1 ''' def collatz(number): ## if number%2==0: ## print(number//2) ## else: ## print(3*number+1) ... 阅读全文
posted @ 2019-08-31 18:26 Andhui 阅读(611) 评论(0) 推荐(0)
摘要:import jieba #第一题 txt='Python是最有意思的编程语言' words=jieba.lcut(txt) #精确分词 words_all=jieba.lcut(txt,cut_all=True) #全分词 words_sh=jieba.lcut_for_search(txt) #搜索分词 print(words) print(words_all) print(word... 阅读全文
posted @ 2019-08-31 15:03 Andhui 阅读(659) 评论(0) 推荐(0)
摘要:一般Python for语句前不加语句,但我在机器学习实战中看到了这两条语句: 多方研究和询问,得到如下解释: 语句featList = [example[i] for example in dataSet]作用为: 将dataSet中的数据按行依次放入example中,然后取得example中的e 阅读全文
posted @ 2019-08-31 09:40 Andhui 阅读(20092) 评论(0) 推荐(0)
摘要:Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。 基本语法是通过 {} 和 : 来代替以前的 % 。 format 函数可以接受不限个参数,位置可以不按顺序。 实例 >>>"{} {}".format("hello", "world") 阅读全文
posted @ 2019-08-31 09:10 Andhui 阅读(2894) 评论(0) 推荐(0)
摘要:import jieba ls="中国是一个伟大的国家,是一个好的国家" print('原始文档为:',ls) counts={} # 定义统计字典 words=jieba.lcut(ls) print('分好的词组为:',words) for word in words: counts[word]=counts.get(word,0)+1 print('生成的字典为:',counts) prin 阅读全文
posted @ 2019-08-30 11:07 Andhui 阅读(2177) 评论(0) 推荐(0)
摘要:1.实现isNum()函数,参数为一个字符串,如果这个字符串属于整数、浮点数或复数的表示,则返回True,否则返回False 2.判断是否为质数 3、输入一个文件和一个字符,统计该字符在文件中出现的次数 阅读全文
posted @ 2019-08-18 08:51 Andhui 阅读(1501) 评论(0) 推荐(0)
摘要:在学习过程中,经常能遇到采用while True的用法。下面以一个例子进行说明: 建立一个用户登录系统,用户输入用户名和密码,如果正确就可以进入系统。 1、我自己最开始的写法: d = {} #数据库字典,所有用户的用户名密码存储在此 name = input("请输入您的用户名:")if name 阅读全文
posted @ 2019-08-04 15:17 Andhui 阅读(30331) 评论(1) 推荐(0)
摘要:1。四位数字字母验证码的生成实例 输出为:m47A、8wQ9、vugS 2。格式化时间函数 3。记录显示登录日志实例 最大公约数:指两个或多个整数共有约数中最大的一个 最小公倍数:两个或多个整数公有的倍数叫做它们的公倍数,其中除0以外最小的一个公倍数就叫做这几个整数的最小公倍数 二者关系:两个数之积 阅读全文
posted @ 2019-08-03 16:13 Andhui 阅读(99884) 评论(1) 推荐(3)
摘要:编程语言中,我们经常会和文件和文件夹打交道,这篇文章主要讲的是Python中,读写文件的常用操作: 一、打开文件 openFile = open('../Files/exampleFile.txt', 'a')说明:1. 第一个参数是文件名称,包括路径,可以是相对路径./,也可以是绝对路径"d:\t 阅读全文
posted @ 2019-08-03 16:00 Andhui 阅读(2091) 评论(0) 推荐(0)
摘要:open/文件操作f=open('/tmp/hello','w')#open(路径+文件名,读写模式)#读写模式:r只读,r+读写,w新建(会覆盖原有文件),a追加,b二进制文件.常用模式如:'rb','wb','r+b'等等 读写模式的类型有: rU 或 Ua 以读方式打开, 同时提供通用换行符支 阅读全文
posted @ 2019-08-03 15:22 Andhui 阅读(1553) 评论(0) 推荐(0)
摘要:stat 系统调用时用来返回相关文件的系统状态信息的。 首先我们看一下stat中有哪些属性: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 >>> import os >>> print os.stat("/root/pyth 阅读全文
posted @ 2019-08-02 15:11 Andhui 阅读(3211) 评论(0) 推荐(1)
摘要:datetime模块用于是date和time模块的合集,datetime有两个常量,MAXYEAR和MINYEAR,分别是9999和1. datetime模块定义了5个类,分别是 1.datetime.date:表示日期的类 2.datetime.datetime:表示日期时间的类 3.dateti 阅读全文
posted @ 2019-07-28 16:23 Andhui 阅读(55015) 评论(1) 推荐(2)
摘要:原文链接:http://blog.51cto.com/hanviseas/2299546 1. 模块与import语句 任何Python源文件都能以模块的形式使用,例如: # spam.py a = 37 def foo(): print("I'm foo and a is %s" % a) def 阅读全文
posted @ 2019-07-28 10:12 Andhui 阅读(425) 评论(0) 推荐(0)
摘要:描述 random() 方法返回随机生成的一个实数,它在[0,1)范围内。 语法 以下是 random() 方法的语法: 注意:random()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。 random() 函数中常见的函数如下: Python 生成随 阅读全文
posted @ 2019-07-27 17:53 Andhui 阅读(5695) 评论(0) 推荐(0)
摘要:pythn print格式化输出。 %r 用来做 debug 比较好,因为它会显示变量的原始数据(raw data),而其它的符号则是用来向用户显示输出的。 1. 打印字符串 print ("His name is %s"%("Aviad"))效果: 2.打印整数 print ("He is %d 阅读全文
posted @ 2019-07-24 15:28 Andhui 阅读(763) 评论(0) 推荐(0)
摘要:特别的 阅读全文
posted @ 2019-07-16 10:20 Andhui 阅读(2530) 评论(0) 推荐(0)
摘要:运算符详解2.1、算术运算符2.2、比较(关系)运算符2.3、赋值运算符2.4、逻辑运算符2.5、位运算符2.6、成员运算符2.7、身份运算符三、重要运算符说明3.1、join和符号”+“区别3.2、is和”==“区别 运算符详解2.1、算术运算符2.2、比较(关系)运算符2.3、赋值运算符2.4、 阅读全文
posted @ 2019-07-16 09:12 Andhui 阅读(15606) 评论(1) 推荐(1)
摘要:用于导入模块,与import结合使用 条件语句,与else,elif结合使用 用于表达式运算,逻辑非操作 阅读全文
posted @ 2019-07-14 22:05 Andhui 阅读(15517) 评论(0) 推荐(0)