随笔分类 -  Python

上一页 1 2 3 4
Python计算不带括号的字符串
摘要:__author__ = 'Alex' # -*- coding:UTF-8 -*- import re import string str = "-10+30-20*11+40*21/5-100+70-2*13+14" data_list=[] sym_list=[] data_list = re.findall('\d+',str) sym_list = re.findall('\D+',... 阅读全文
posted @ 2016-05-13 22:24 Alex0425 阅读(651) 评论(0) 推荐(0)
Python 正则表达式
摘要:def match(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object, or None if no match was found." 阅读全文
posted @ 2016-05-11 01:43 Alex0425 阅读(175) 评论(0) 推荐(0)
Python 矩阵的旋转
摘要:Array = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]print (Array)for i in range(len(Array)): for j in range(i,len(Array[i])): tmp = Array[i][j] Ar 阅读全文
posted @ 2016-05-09 18:02 Alex0425 阅读(816) 评论(0) 推荐(0)
Python 装饰器
摘要:welcome to loginwelcome [Alex] to tv page 结论:1.先定义一个login函数,形参为函数的地址,返回值也为函数地址。 welcome to loginwelcome [Alex] to tv page 结论:这里的@login等同于tv = login(tv 阅读全文
posted @ 2016-05-06 02:02 Alex0425 阅读(197) 评论(0) 推荐(0)
Python 生产者和消费者模型
摘要:A consumer one productB consumer one productbegin to make baozimake two baozibaozi[0] bei [A] chilebaozi[0] bei [B] chilemake two baozibaozi[1] bei [A 阅读全文
posted @ 2016-05-05 22:51 Alex0425 阅读(215) 评论(0) 推荐(0)
Python 迭代器和生成器
摘要:1 1 2 3 5 Traceback (most recent call last): File "D:/Python/day3/Test.py", line 20, in <module> print (f.__next__()) StopIteration 查看另外一个例子“ 1 first 阅读全文
posted @ 2016-05-05 00:33 Alex0425 阅读(196) 评论(0) 推荐(0)
Python json模块
摘要:<class 'list'> [11, 22, 33, 44] <class 'dict'> {'k2': 'v2', 'k1': 'v1'} 结论:json可以将字符串格式化为相应的数据类型 阅读全文
posted @ 2016-05-03 20:36 Alex0425 阅读(191) 评论(0) 推荐(0)
Python 内部函数
摘要:(10, 'alex') (11, 'eric') (12, 'Roman') 结论: enumerate方便给元素添加一个自增的序号 99 c 结论:ord可以将字符转为ascii码,chr可以将ascii转为字符串 [[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]] 阅读全文
posted @ 2016-05-02 00:40 Alex0425 阅读(258) 评论(0) 推荐(0)
Python lambda表达式
摘要:def fun(a): a = a +1 return aprint (fun(4))结果:5fun2 = lambda a:a+1 #冒号前为形参,可以是多个;冒号后面的函数体print (fun2(18))结果:19 阅读全文
posted @ 2016-05-01 12:14 Alex0425 阅读(256) 评论(0) 推荐(0)
Python 函数动态参数
摘要:([11, 22, 33], [44], ['a', 'b']) <class 'tuple'> {'k2': 'v2', 'k1': 'v1'} <class 'dict'> 结论:同时传递两个带*号的参数,在形参定义里,第一个形参只能是带一个*号,第二个形参只能是带两个*号,同时在参数传递的时候 阅读全文
posted @ 2016-05-01 10:17 Alex0425 阅读(444) 评论(0) 推荐(0)
python 邮件发送
摘要:#!/usr/bin/env python # -*- coding:UTF-8 -*- #需要在邮箱处设置开启SMTP服务(第三方客户端发送) import smtplibfrom email.mime.text import MIMETextfrom email.utils import for 阅读全文
posted @ 2016-05-01 09:12 Alex0425 阅读(192) 评论(0) 推荐(0)
Python 深浅拷贝
摘要:1.针对字符和数字的赋值,深拷贝与浅拷贝 24266496 24266496 结论:对于赋值操作,内存地址是一致的。 5129984 5129984 结论:对于浅拷贝,内存地址也是一致的 24069888 24069888 结论:对于深拷贝,内存地址也是一致的 2.针对列表,元祖与字典的赋值,深拷贝 阅读全文
posted @ 2016-04-30 14:21 Alex0425 阅读(169) 评论(0) 推荐(0)
Python collections类
摘要:Counter({'a': 5, 'b': 4, 'c': 3, 'd': 2, 'e': 1}) a 5 c 3 e 1 d 2 b 4 结论:统计各个字符串出现的次数 OrderedDict {'k1': [11, 22, 33, 44, 55]} {'k2': [66, 77, 88, 99] 阅读全文
posted @ 2016-04-30 13:19 Alex0425 阅读(251) 评论(0) 推荐(0)
Python str内部功能介绍
摘要:T:h:i:s: :I:s: :S:t:r:i:n:g: :E:x:a:m:p:l:e:.:.:.:W:o:w:!:!:! This:is:a:book This:is:a:book 2-4-1-3 <class 'dict'> {97: 49, 98: 50, 99: 51, 100: 52, 1 阅读全文
posted @ 2016-04-30 00:24 Alex0425 阅读(448) 评论(0) 推荐(0)
Python set集合
摘要:{1, 2, 3, 4, 5}{3, 4, 6}{1, 2, 5} 结论:difference计算在s1集合中但是不在s2集合中的内容,并且生成一个新的集合s3,原来s1,s2不变 {1, 2, 5}{3, 4, 6}None 结论:difference_update计算了在s1集合中但是不在s2集 阅读全文
posted @ 2016-04-29 01:55 Alex0425 阅读(409) 评论(0) 推荐(0)

上一页 1 2 3 4