字符串的操作
取出字符串中的其中一个字符
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)