首页 > 代码库 > python3.4 data type
python3.4 data type
#coding=utf-8#Python 3.4 https://docs.python.org/3.4/library/#IDE:Eclipse +PyDev Window10import atexitimport osimport sysimport timeimport winsoundimport codeimport codecsimport mathimport csvimport base64import reimport smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.header import Header from email.mime.image import MIMEImagefrom email.mime.base import MIMEBase from email.utils import COMMASPACE, formatdate import emailimport os.path import mimetypes import configparserimport stringimport nltk import simhashimport uuidimport socketimport functoolsimport fnmatchimport timeimport datetimeimport calendarimport psycopg2from datetime import timedeltaimport randomimport unicodedatafrom decimal import * import MailSender #自定义类import choices #自定义类from jump import longprint("涂聚文,geovindu") #中文显示必需文件编码格式utf-8#获取本机电脑名myname = socket.getfqdn(socket.gethostname( ));#获取本机ipmyaddr = socket.gethostbyname(myname);print(myname);print(myaddr);#Data Typesprint ("hello word 你好,世界");print (sys.platform);print (2 ** 100);#输入try: userimput = input("输入的内容: ") #PyDevexcept NameError: passprint("你好:"+userimput);print(type(userimput));#类型nowTime=time.localtime();nowDate=datetime.datetime(nowTime[0],nowTime[1],nowTime[2]);datasd=["Acme",50,99.8,"2012-12-21",(2015,12,20)];productname,productshares,productprice,productdate,productdate2=datasd;print("产品名称:"+productname);print("产品数量:"+str(productshares));print("产品价格:"+str(productprice));print("产品日期:"+productdate); #datetime.datetime.strptimedate1=datetime.datetime(2015,12,20);print(type(nowTime)); #time.struct_timeprint(type(nowDate)); #atetime.datetimeprint(type(productdate2)); #tupleprint(type(productdate)); #strprint(date1);print(time.strftime("%Y-%m-%d %H:%M:%S",nowTime)); #%Y-%m-%d %H:%M:%S %fprint(nowDate);#print("time %" % nowDate);print(time.strptime(productdate,"%Y-%m-%d")); ##字符串转换成time类型 %Y-%m-%d %H:%M:%Sdate2=time.strptime(productdate,"%Y-%m-%d");print(nowDate.strftime("%Y-%m-%d")); ##time类型转换成字符串类型 %y-%m-%d %I:%M:%S %p print(date2);print(type(date2));d = timedelta(microseconds=-1);print(d.days, d.seconds, d.microseconds); # -1 86399 999999year = timedelta(days=365);another_year = timedelta(weeks=40, days=84, hours=23,minutes=50, seconds=600); # adds up to 365 daysprint(year.total_seconds()); #31536000.0print(year == another_year);dt = datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M");tt = dt.timetuple();‘‘‘2006 # year11 # month21 # day16 # hour30 # minute0 # second1 # weekday (0 = Monday)325 # number of days since 1st January-1 # dst - method tzinfo.dst() returned None‘‘‘for it in tt: print (it);ic = dt.isocalendar();‘‘‘2006 # ISO year47 # ISO week2 # ISO weekday‘‘‘for ff in ic: print(ff);print(calendar.setfirstweekday(calendar.SUNDAY)); #None#https://docs.python.org/3/library/index.htmld = Decimal(15.6);print(d+80);ra=random.randrange(0,12001,5); # Even integer from 0 to 1200 inclusive 从0至12000,5位数的随机数 11435print(ra);mood = choices.PDist([(‘happy‘, 0.3), (‘neutral‘, 0.6), (‘sad‘, 0.1)]) #随机选取字符串print(mood());rstr=random.choice(["geovindu","du","涂聚文","geovi"]); #随机选取字符串print(rstr);deck = ‘ace two three four‘.split();random.shuffle(deck); # Shuffle a list 洗牌print(deck);du=int(2);print(du*20);du=long(200);print(du/20);du=float(2500.25);print(du-200);
python3.4 data type
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。