标签:合取 import odi 注意 join 日期 font pytho 开始时间
一、Time模块
1.时间戳
2.time.time()
import time print time.time() -->1572350849.07
3.time.localtime()
import time #不带参数 print time.localtime() -->time.struct_time(tm_year=2019, tm_mon=10, tm_mday=29, tm_hour=20, tm_min=12, tm_sec=47, tm_wday=1, tm_yday=302, tm_isdst=0) #带参数 print time.localtime(30) -->time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=0, tm_sec=30, tm_wday=3, tm_yday=1, tm_isdst=0)
4.time.asctime()
#带参数 import time a = time.localtime(30) #返回为时间元组 print time.asctime(a) #不带参数 import time print time.asctime()
5.time.strftime()
import time #默认返回的是格式化后的时间 print time.strftime("%Y-%m-%d %H:%M:%S") #返回的是给定的时间元组所转化成的格式化时间 import time a = time.localtime(30) print time.strftime("%Y-%m-%d %H:%M:%S",a) #封装返回当前格式化时间的函数 import time def local_time(): return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
python中时间日期格式化符号:
6.time.strptime(str,str_fmt)
#coding=utf-8 import time A = time.strftime("%Y-%m-%d %H:%M:%S") #返回的是格式化后的时间 print time.strptime(A,"%Y-%m-%d %H:%M:%S") #将格式化后的时间转化为时间元组
7.time.mktime(tupletime)
#coding=utf-8 import time A = time.strftime("%Y-%m-%d %H:%M:%S") #返回的是格式化后的时间 B = time.strptime(A,"%Y-%m-%d %H:%M:%S") #将格式化后的时间转化为时间元组 print time.mktime(B) #返回的是时间戳
8.time.sleep(s) 延时
print 1 time.sleep(3) #暂停 print 2 time.sleep(3) print 3
二、Random模块
1.random.random()
import random print random.random() -->0.112499651779
2.random.randint(x,y)
import random print random.randint(1,2) -->2
3.random.randrange(a,b,step)
import random print random.randrange(3) print random.randrange(1,2) print random.randrange(1,6,2)
4.random.uniform(a,b)
import random print random.uniform(1,2)
5.random.choice(a)
import random a = "xfs" print random.choice(a) b = [1,2,3] print random.choice(b)
""" #随机生成学员姓名 student = [‘张三‘,‘李四‘,‘王五‘,] print random.choice(student) """ """ #随机删除列表中一个字符串,直至列表清空 box = ["a","b","c","d","e","f"] for i in range(len(box)): ball = random.choice(range(len(box))) del box[ball] print box """ """ #随机生成手机号 def phone(): a = ["136","177","186","131"] return random.choice(a)+"".join(random.choice("0123456789") for i in range(8)) """ """ #10内相加计算 import random a = random.randint(1,10) b = random.randint(1,10) c = raw_input(str(a) + "+" + str(b) + "=") if int(c) == a+b: print "答案正确!" else: print "答案错误!" """ """ #福利彩票生成 num = ["1","2","3",‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘10‘,‘11‘,‘12‘,‘13‘,‘14‘,‘15‘,‘16‘, ‘17‘,‘18‘,‘19‘,‘20‘,‘21‘,‘22‘,‘23‘,‘24‘,‘25‘,‘26‘,‘27‘,‘28‘,‘29‘, ‘30‘,‘31‘,‘32‘,‘33‘] for i in range(7): num1 = num.pop(random.randint(0,len(num)-1)) if i == 0: num2 = num1 elif i == 1: num3 = num1 elif i == 2: num4 = num1 elif i == 3: num5 = num1 elif i == 4: num6 = num1 elif i == 5: num7 = num1 elif i == 6: num8 = num1 print num2+" "+num3+" "+num4+" "+num5+" "+num6+" "+num7+" "+num8 """
标签:合取 import odi 注意 join 日期 font pytho 开始时间
原文地址:https://www.cnblogs.com/Mr-ZY/p/11761422.html