随笔分类 -  Python

Writing and Writing
摘要:在pycharm中是自动补全的变量的类别p:parameter 参数m:method方法c:class 类v:variable 变量f:function 函数 从定义的角度上看,我们知道函数(function)就相当于一个数学公式,它理论上不与其它东西关系,它只需要相关的参数就可以。所以普通的在mo 阅读全文
posted @ 2017-06-01 10:14 JustLittle 阅读(342) 评论(0) 推荐(0) 编辑
摘要:§对于绝大多数情况下,在函数内部直接修改形参的值不会影响实参。例如: >>> def addOne(a): print(a) a += 1 print(a) >>> a = 3 >>> addOne(a) 3 4 >>> a 3 §在有些情况下,可以通过特殊的方式在函数内部修改实参的值,例如下面的代 阅读全文
posted @ 2017-06-01 09:31 JustLittle 阅读(4454) 评论(0) 推荐(0) 编辑
摘要:Please use me as a module[2, 4, 8, 12, 14] 阅读全文
posted @ 2017-05-31 21:25 JustLittle 阅读(448) 评论(0) 推荐(0) 编辑
摘要:__new__() 类的静态方法,用于确定是否要创建对象__init__() 构造函数,生成对象时调用__del__() 析构函数,释放对象时调用__add__() +__sub__() -__mul__() *__truediv__() /__floordiv__() //__mod__() %_ 阅读全文
posted @ 2017-05-31 17:08 JustLittle 阅读(346) 评论(0) 推荐(0) 编辑
摘要:11self.__value: 3Root.__total: 122self.__value: 3Root.__total: 2self.__value: 3Root.__total: 2self.__value: 5Root.__total: 2self.__value: 5Root.__tota 阅读全文
posted @ 2017-05-31 14:07 JustLittle 阅读(410) 评论(0) 推荐(0) 编辑
摘要:方法用来描述对象所具有的行为,例如,列表对象的追加元素、插入元素、删除原宿、排序,字符串对象的分隔、连接、排版、替换、烤箱的温度设置、烘烤,等等 在类中定义的方法可以粗略分为四大类:公有方法、私有方法、静态方法和类方法。公有方法、私有方法一般是指属于对象的实例方法,其中私有方法的的名字以两个下划线( 阅读全文
posted @ 2017-05-31 11:51 JustLittle 阅读(1899) 评论(0) 推荐(0) 编辑
摘要:>>> def main(n): start = 10**(n-1)+2 end = start*10-20 for i in range(start,end): i = str(i) big = ''.join(sorted(i,reverse=True)) big = int(big) litt 阅读全文
posted @ 2017-05-31 09:01 JustLittle 阅读(1542) 评论(0) 推荐(0) 编辑
摘要:'''据说古代有一个梵塔,塔内有三个底座A、B、C,A座上有64个盘子,盘子大小不等,大的在下,小的在上。有一个和尚想把这64个盘子从A座移到C座,但每次只能允许移动一个盘子,在移动盘子的过程中可以利用B座,但任何时刻3个座上的盘子都必须始终保持大盘在下、小盘在上的顺序。如果只有一个盘子,则不需要利 阅读全文
posted @ 2017-05-31 08:50 JustLittle 阅读(1471) 评论(0) 推荐(0) 编辑
摘要:>>> def printMax(a,b): if a>b: print(a,'is the max') else: print(b,'is hte max') >>> def addOne(a): print(a) a+=1 print(a) >>> a=3>>> addOne(a)34>>> d 阅读全文
posted @ 2017-05-25 15:22 JustLittle 阅读(319) 评论(0) 推荐(0) 编辑
摘要:1 >>> def check_permission(func): 2 def wrapper(*args,**kwargs): 3 if kwargs.get('username')!='admin': 4 raise Exception('Sorry.You are not allowed.') 5 return func(*args,**kwargs) 6 return wra... 阅读全文
posted @ 2017-05-25 09:29 JustLittle 阅读(310) 评论(0) 推荐(0) 编辑
摘要:>>> from datetime import date>>> daysOfMonth=[31,28,31,30,31,30,31,31,30,31,30,31] >>> def myCalendar(year,month): start=date(year,month,1).timetuple( 阅读全文
posted @ 2017-05-24 14:18 JustLittle 阅读(345) 评论(0) 推荐(0) 编辑
摘要:>>> import datetime>>> Today=datetime.date.today()>>> Todaydatetime.date(2017, 5, 24)>>> Today-datetime.date(Today.year,1,1)+datetime.timedelta(days=1 阅读全文
posted @ 2017-05-24 13:45 JustLittle 阅读(150) 评论(0) 推荐(0) 编辑
摘要:>>> if 3>2:print('ok') ok>>> if True:print(3);print(5) 35>>> chTesst=['1','2','3','4','5']>>> if chTesst: print(chTesst)else: print('Empty') ['1', '2' 阅读全文
posted @ 2017-05-23 21:11 JustLittle 阅读(4483) 评论(0) 推荐(0) 编辑
摘要:>>> import random>>> import time>>> x=list(range(10000))>>> y=set(range(10000))>>> z=dict(zip(range(1000),range(10000)))>>> r=random.randint(0,9999)>> 阅读全文
posted @ 2017-05-22 22:00 JustLittle 阅读(241) 评论(0) 推荐(0) 编辑
摘要:>>> import string>>> import random #组合字符>>> x=string.ascii_letters+string.digits+string.punctuation>>> x'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS 阅读全文
posted @ 2017-05-22 14:34 JustLittle 阅读(349) 评论(0) 推荐(0) 编辑
摘要:>>> seq=['foo','x41','?','***']>>> def func(x): return x.isalnum() >>> list(filter(func,seq))['foo', 'x41']>>> seq['foo', 'x41', '?', '***']>>> [x for 阅读全文
posted @ 2017-05-20 22:05 JustLittle 阅读(316) 评论(0) 推荐(0) 编辑
摘要:>>> import math>>> math.sin(0.5)0.479425538604203>>> >>> import random>>> x=random.random()>>> n=random.randint(1,100)>>> import numpy as np>>> a = np 阅读全文
posted @ 2017-05-19 17:37 JustLittle 阅读(210) 评论(0) 推荐(0) 编辑
摘要:>>> def is_not_empty(s): return s and len(s.strip()) > 0 >>> filter(is_not_empty, ['test', None, '', 'str', ' ', 'END'])<filter object at 0x1056a3518> 阅读全文
posted @ 2017-05-18 20:51 JustLittle 阅读(462) 评论(0) 推荐(0) 编辑