随笔分类 -  python

摘要:# 一、 装饰器## 3.函数即变量:在Python中,函数就是一个变量,函数名就是一个变量,这个函数名里面存的是这个函数的内存地址,它把函数体放到内存里,在调用的时候从函数名里面的这个内存地址找到函数体然后运行这个函数(函数名加上括号就是调用这个函数,如果只写这个函数名就是打印一下这个函数的内存地 阅读全文
posted @ 2019-02-12 10:46 13684995613 阅读(238) 评论(0) 推荐(0)
摘要:一、异常处理 在程序运行过程中,总会遇到各种各样的错误。程序一旦出错就停止运行了,此时就需要捕捉异常,通过捕捉到的异常,我们再去做对应的处理 写一个函数,实现除法运算 def calc(a,b): return a/b print(calc(5,1))#调用,没有错误,结果是5.0 >>> 5.0 阅读全文
posted @ 2019-02-12 10:36 13684995613 阅读(2830) 评论(0) 推荐(0)
摘要:环境是win8,原来只安装了python2.7。后来因为要用到python3,为了让两者共存,降python3的运行文件改成了python3.exe. 问题就此而来,这时候运行python3 的pip会遇到如下错误 Fatal error in launcher: Unable to create 阅读全文
posted @ 2018-06-22 15:19 13684995613 阅读(2355) 评论(0) 推荐(0)
摘要:#插入排序(将一个数据插入到已经排好序的有序数据中,从而得到一个新的、个数加一的有序数据)# def insert_sort(list):# count = len(list) #算出列表长度用于控制循环次数# for i in range(1,count):# key = list[i] #列表中 阅读全文
posted @ 2017-12-12 18:14 13684995613 阅读(143) 评论(0) 推荐(0)
摘要:出自:http://www.nonb.cn/blog/python-bonus.htmlimport random,sysdef HB(min,max,total,num): print(min,max,total,num) total = float(total) num = int(num) m 阅读全文
posted @ 2017-12-04 15:38 13684995613 阅读(187) 评论(0) 推荐(0)
摘要:C:\Users\MOJIE\AppData\Local\Programs\Python\Python36\python.exe C:/Users/MOJIE/PycharmProjects/test/tee.py90poi9jdklsmjjff932kbhj00222221okmf00222221 阅读全文
posted @ 2017-12-03 21:56 13684995613 阅读(371) 评论(0) 推荐(0)
摘要:import pymysql,redisdef OpertioMsql(host,user,passwd,db,sql,port=3306,charset='utf8'): conn = pymysql.connect(host=host,user=user,passwd=passwd,port=p 阅读全文
posted @ 2017-09-29 16:51 13684995613 阅读(188) 评论(0) 推荐(0)
摘要:def maoPao(list): print(list) for a in range(len(list)): #控制外循环次数 for i in range(a): #循环列表内容 if list[i]>list[i+1]: #前一个数和后一个数进行对比 list[i],list[i+1]=li 阅读全文
posted @ 2017-09-25 17:49 13684995613 阅读(175) 评论(0) 推荐(0)
摘要:一、os模块>>> os.getcwd() #获取当前路径'C:\\Users\\xiu\\AppData\\Local\\Programs\\Python\\Python36-32'>>> os.chdir('C:\\Users\\xiu\\AppData\\Local\\Programs\\Py 阅读全文
posted @ 2017-09-22 18:02 13684995613 阅读(167) 评论(0) 推荐(0)
摘要:#1、python中使用正则表达式步骤:import re #导入正则表达式模块# ff = re.compile(r'\d{3}-\d{3}-\d{4}') #用compile函数创建一个Regex对象# gg = ff.search('my phone is:075-333-4466') #像R 阅读全文
posted @ 2017-09-14 15:57 13684995613 阅读(196) 评论(0) 推荐(0)
摘要:# 1.像列表一样,字典是许多值的集合,存储方式“键-值”对# mycat = {'size':'fat','color':'red','disposition':'loud'}# 这个字典的键:size、color、disposition# 这个字典的值:fat、red、loud# 根据“键”获取 阅读全文
posted @ 2017-09-13 17:30 13684995613 阅读(183) 评论(0) 推荐(0)
摘要:# 1.直接赋值,传递对象的引用而已,原始列表改变,被赋值的变量也会做相同的改变A=[1,2,3,4,5,['aa','bb','cc']]a = AA.append('ee')print(A) #[1, 2, 3, 4, 5, ['aa', 'bb', 'cc'], 'ee']print(a) # 阅读全文
posted @ 2017-08-31 19:04 13684995613 阅读(182) 评论(0) 推荐(0)
摘要:列表 “列表”是一个值,它包含多个字构成的序列。术语“列表值”指的是列表本身(它作为一个值,可以保存在变量中、传递给函数)--:按下标取值、切片、for循环、用于len()以及in not in等 list ['aa','bb','cc','dd']是一个简单的列表 1.用列表下标取值 list = 阅读全文
posted @ 2017-08-07 18:50 13684995613 阅读(440) 评论(0) 推荐(0)
摘要:#读取excel# import xlrd #导入读excel的模块# book = xlrd.open_workbook('szz.xls') #建立excel链接# sheet = book.sheet_names() #获取所有的sheet页# sheet = book.sheet_by_index(0) #根据sheet页的位置取sheet页# sheet = book.sheet_b... 阅读全文
posted @ 2017-07-05 18:06 13684995613 阅读(149) 评论(0) 推荐(0)
摘要:#1+2+3+...100# sum = 0# n = 1# while n < 101:# sum = sum + n# n +=1# print(sum)#1+2+3+...100# sum = 0# for n in range(1,101):# sum = sum +n# print(sum 阅读全文
posted @ 2017-06-29 16:18 13684995613 阅读(187) 评论(0) 推荐(0)
摘要:# 1、写一个函数,批量生成一些注册使用的账号:产生的账号是以@163.com结尾,长度由用户输入,产生多少条也由用户输入,用户名不能重复,用户名必须由大写字母、小写字母、数字组成 import random,stringdef Users(num,len): result = [] a = str 阅读全文
posted @ 2017-06-29 12:05 13684995613 阅读(1114) 评论(0) 推荐(0)
摘要:1、Python3操作MySQL数据库需要安装一个第三方模块(pymysql):pip install pymysql;操作redis需要安装redis模块(redis):pip install redis Python操作MySQL: 阅读全文
posted @ 2017-06-27 16:42 13684995613 阅读(579) 评论(0) 推荐(0)
摘要:Python是一门面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年。 解释型:在运行的时候将程序翻译成机器语言,所以运行速度相对于编译型语言要慢。如:Python/JavaScript / Perl /Shell/C#/j 阅读全文
posted @ 2017-05-19 14:25 13684995613 阅读(368) 评论(0) 推荐(0)