Python_2
应该修改为:'There's a snake in my boot!'
2. 每一个字符串里的字符都会有对应的index'There\'s a snake in my boot!'
3. string methods:c = "cats"[0]
n = "Ryan"[3]
注意这里print的用法parrot = "Norwegian Blue" print len(parrot)
(3)upper() 将字符串中所有的小写字符变为大写字符。"Ryan".lower()
(4) str() 将非字符串转变为字符串print parrot.upper()
str(2)
dot notation: Methods that use dot notation only work with strings. low() 和 upper() 只能应用于字符串的变量;len() 和 str() 可以用于其他类型。
ministry = "The Ministry of Silly Walks" print len(ministry) print ministry.upper()
4. console :编辑器中显示结果的窗口
concatenation : 用加号连接字符串
print "Life " + "of " + "Brian"
print "I have " + str(2) + " coconuts!"
name = "Mike"
print "Hello %s" % (name)
print 的标准写法,%后面有空格,变量用()括起来。
string_1 = "Camelot" string_2 = "place" print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)
print使用“”是为了防止’的干扰,变量均在()中。
6.创建字符三种方式:1.' ' 2." " 3.str()print "Ah, so your name is %s, your quest is %s, " \ "and your favorite color is %s." % (name, quest, color)
8. 获取当前时间:from datetime import datetime
9. 取出年,月,日,直接在获得变量后面 dot notationfrom datetime import datetime now = datetime.now() print now
10. colons:冒号from datetime import datetime now = datetime.now() print now print now.year print now.month print now.day
print '%s:%s:%s' % (now.hour, now.minute, now.second)