python3.4 data type
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3.4 data type相关的知识,希望对你有一定的参考价值。
#coding=utf-8 #Python 3.4 https://docs.python.org/3.4/library/ #IDE:Eclipse +PyDev Window10 import atexit import os import sys import time import winsound import code import codecs import math import csv import base64 import re import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from email.mime.image import MIMEImage from email.mime.base import MIMEBase from email.utils import COMMASPACE, formatdate import email import os.path import mimetypes import configparser import string import nltk import simhash import uuid import socket import functools import fnmatch import time import datetime import calendar import psycopg2 from datetime import timedelta import random import unicodedata from decimal import * import MailSender #自定义类 import choices #自定义类 from jump import long print("涂聚文,geovindu") #中文显示必需文件编码格式utf-8 #获取本机电脑名 myname = socket.getfqdn(socket.gethostname( )); #获取本机ip myaddr = socket.gethostbyname(myname); print(myname); print(myaddr); #Data Types print ("hello word 你好,世界"); print (sys.platform); print (2 ** 100); #输入 try: userimput = input("输入的内容: ") #PyDev except NameError: pass print("你好:"+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.strptime date1=datetime.datetime(2015,12,20); print(type(nowTime)); #time.struct_time print(type(nowDate)); #atetime.datetime print(type(productdate2)); #tuple print(type(productdate)); #str print(date1); print(time.strftime("%Y-%m-%d %H:%M:%S",nowTime)); #%Y-%m-%d %H:%M:%S %f print(nowDate); #print("time %" % nowDate); print(time.strptime(productdate,"%Y-%m-%d")); ##字符串转换成time类型 %Y-%m-%d %H:%M:%S date2=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 999999 year = timedelta(days=365); another_year = timedelta(weeks=40, days=84, hours=23,minutes=50, seconds=600); # adds up to 365 days print(year.total_seconds()); #31536000.0 print(year == another_year); dt = datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M"); tt = dt.timetuple(); ‘‘‘ 2006 # year 11 # month 21 # day 16 # hour 30 # minute 0 # second 1 # 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 year 47 # ISO week 2 # ISO weekday ‘‘‘ for ff in ic: print(ff); print(calendar.setfirstweekday(calendar.SUNDAY)); #None #https://docs.python.org/3/library/index.html d = Decimal(15.6); print(d+80); ra=random.randrange(0,12001,5); # Even integer from 0 to 1200 inclusive 从0至12000,5位数的随机数 11435 print(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的主要内容,如果未能解决你的问题,请参考以下文章
python-geoip 在 python3.4 上不起作用?
Failed to convert property value of type ‘java.lang.String‘ to required type ‘int‘ for property(代码片段
[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段
SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段