exercise 10

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_cat
print persian_cat
print backslash_cat
print 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值