Python 精巧知识点备忘
2015-06-04 11:11
441 查看
字符串的操作
取出字符串中的其中一个字符string = "Python" #取出第一个字符 first = string[0] #或者 first = "Python"[0]
转换为字符串
#str() pi = 3.14 print str(pi)
字符串串联:+
print "Spam "+"and "+"eggs" #打印一个字符串和变量 string_1 = "Camelot" string_2 = "place" print "Let's not go to %s. It\' a silly %s."%(string_1,string_2) #字符串直接带入 print "The %s who %s %s!" % ("Knights", "say", "Ni")
datetime 库
from datetime import datetime #备注:打印的不是北京时间 print datetime.now() #打印部分时间,年或者月或者时间点 from datetime import datetime now = datetime.now() print now.year print now.month print now.day print '%s:%s:%s' % (now.year, now.month, now.day) print '%s/%s/%s' % (now.month, now.day, now.year) print '%s:%s:%s' % (now.hour, now.minute, now.second) #打印时间格式如下:mm/dd/yyyy hh:mm:ss print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year,now.hour, now.minute, now.second)
相关文章推荐
- python创建进程fork用法
- pydev+eclipse+python3.4运行hello word,提示Error in sitecustomize; set PYTHONVERBOSE for traceback:
- Python文件及目录操作实例详解
- python 中如何判断list中是否包含某个元素
- python
- 一张图让你学会Python
- Python通过poll实现异步IO的方法
- Python通过select实现异步IO的方法
- Python模拟RSA算法
- python同时标准输出和重定向到文件保存
- Python守护进程用法实例分析
- Python使用multiprocessing创建进程的方法
- python中以特殊颜色打印文本
- python在windows下创建隐藏窗口子进程的方法
- python错误总结大全--(一)
- Python爬虫入门一之综述
- 用python去除图片白色像素
- Python自学笔记之函数式编程1——高阶函数
- python 读写文件
- Sublime Text3配置在可交互环境下运行python快捷键