随笔分类 - Python
摘要:程序片段1 第一个需求是需要生成一些随机的时间,例如需要随机生成从一年前到现在的一些时间,刚开始折腾了半天,最后的代码如下: from datetime import timedelta from datetime import date import random (datetime.dateti
阅读全文
摘要:Print sorted list:colors=['red','green','blue','yellow']for color in sorted(colors): print colorfor color in sorted(colors,reverse=True): print ...
阅读全文
摘要:Looping over a range of numbersBad:for i in [0,1,2,3,4,5]: print i**2Good:for i in range(6): print i**2Looping over a collection:Bad:colors = [ ...
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two.My initial code: 1 class Solution: 2 # @param {integer} n 3 # @return ...
阅读全文
摘要:今天有个需求时需要为某个类设置缺省值最开始的代码如下:Class myClass def __init__(self,datalen=None,times=None): if datalen == None : self.datalen = 1024 ...
阅读全文