exercise 10

来源:互联网 发布:联通客服上门调网络 编辑:程序博客网 时间:2024/04/28 01:22
print "I am 6'2\" tall."  \" to mean" in case mistake with ending
print 'I am 6\'2" tall.'tabby_cat="\t I'm tabbed in." persian_cat="I'm split\non a line."backslash_cat="I'm \\ a \\ cat."fat_cat = """I'll do a list:\t* Cat food\t* Fishies\t* Catnip\n\t* Grass"""print tabby_catprint persian_catprint backslash_catprint fat_cat

Here's a tiny piece of fun code to try out:

while True:    for i in ["/","-","|","\\","|"]:        print "%s\r" % i,
解释:\r表示回到行首 所以循环输出 | // | - / 上面倒着顺序?????
转义字符和格式化字符串放一起创建更加复杂的格式。
persian_cat = "I'm spliton\v %s line." % "a"
还记得%r吗?%r搭配单引号和双引号转义字符,并且打印出来。比较%r和%s,%r打印你要写到文件里的样子,%s打印你想看到的样子。
persian_cat = "I\'m spliton \"%s\" %r." % ("a", "line")
输出:
I'm spliton "a" 'line'.
注意line有个单引号,表示你要写入程序的是个字符串。
转义字符
\(在行尾) 续行,表示不换行
\\ 反斜杠
\' 单引号
\" 双引号
\a 响铃
\b 退格,表示删除前面一个字符
\t 水平制表符
\v 垂直制表符,表示换行,然后从\v的地方开始输出。
\n 换行
\f 换页
\r 回车 回到行首
EscapeWhat it does.\\Backslash (\)\'Single-quote (')\"Double-quote (")\aASCII bell (BEL)\bASCII backspace (BS)\fASCII formfeed (FF)\nASCII linefeed (LF)\N{name}Character named name in the Unicode database (Unicode only)\rCarriage Return (CR)\tHorizontal Tab (TAB)\uxxxxCharacter with 16-bit hex value xxxx (u'' string only)\UxxxxxxxxCharacter with 32-bit hex value xxxxxxxx (u'' string only)\vASCII vertical tab (VT)\ooo
Character with octal value ooo
\xhhCharacter with hex value hh
0 0