Python
小沈哥
java开发
展开
-
python 日期API
Python 日期函数 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.now() now.strftime('%Y-%m-%d %H:%M:%S') 输出 '2015-04-07 19:11:21' strftime是datetime类的实例方法。原创 2017-08-16 15:31:22 · 479 阅读 · 0 评论 -
Python 字符串函数
Python 字符串函数 生成字符串变量 str='python String function' 字符串长度获取:len(str) 例:print '%s length=%d' % (str,len(str)) 连接字符串 sStr1 = 'strcat' sStr2 = 'append' sStr1 += sStr2 print sStr1 复制字符串原创 2017-08-16 15:37:26 · 171 阅读 · 0 评论 -
Python print格式化输出
Python print格式化输出 1.格式化输出整数 python print也支持参数格式化,与C言的printf似, strHello = "the length of (%s) is %d" %(Hello World,len(Hello World)) print strHello #输出果:the length of (Hello World) is 11原创 2017-08-16 15:43:52 · 446 阅读 · 0 评论 -
Python数据类型转换
Python数据类型转换 Python提供的基本数据类型主要有:布尔类型、整型、浮点型、字符串、列表、元组、集合、字典、日期等等 函数 描述 type(x) x的数据类型 int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换原创 2017-08-16 15:40:04 · 218 阅读 · 0 评论 -
Python 导出EXCEL
Python 导出Excel exportExcel.py #! /usr/bin/python #! -*- coding: utf-8 -*- __auther__ = 'xiaoshenge' import datetime,time import sys import MySQLdb import xlrd import xlwt import calendar import xl原创 2017-08-18 13:21:19 · 672 阅读 · 0 评论 -
Python (io)读取文件
Python (io)读取文件 1.open 使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。 file_object = open('thefile.txt') try: all_the_text = file_object.read( ) finally: file_obj原创 2017-08-16 15:45:40 · 225 阅读 · 0 评论 -
python 列表、元组、字典 增删改查 等常用操作
python 列表、元组、字典 增删改查 等常用操作 #coding=utf-8 #列表 string = 'list' #字符串->列表 list1 = list(string) # ['l', 'i', 's', 't'] #列表->字符串 string1 = ''.join(list1) #list #列表的增删改转载 2017-08-18 18:08:16 · 408 阅读 · 0 评论