python-5.原样输出,转义字符(python中转义字符用法及例子)

网友投稿 420 2022-08-26


python-5.原样输出,转义字符(python中转义字符用法及例子)

exercise 9

python换行符,\n,tab制表符\t 多行文本原样输出.不解析变量,但是换行符号,转义字符仍旧生效,与php里面的nowdoc类似.三个单引号与三个双引号作用一样.

# Here's some new strange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print("Here are the days:",days)print("Here are the months:",months)print('''There's something 'dfs '' going on here. "{months}"\tWith the three double quots. {days}We'll be able to type as much as we like.\nEven 4 lines if we want, or 5, ""asdas"" or 6.''')

exercise 10

tabbly_cat = "\tI'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(tabbly_cat)print(persian_cat)print(backslash_cat)print(fat_cat)

python支持的转义字符串:

Escape

What it does.

\

Backslash ()


Single-quote (’)

"

Double-quote (")

\a

ASCII bell (BEL)

\b

ASCII backspace (BS)

\f

ASCII formfeed (FF)

\n

ASCII linefeed (LF)

\N

{name} Character named name in the Unicode database

\r

Carriage return (CR)

\t

Horizontal tab (TAB)

\uxxxx

Character with 16-bit hex value xxxx

\Uxxxxxxxx

Character with 32-bit hex value xxxxxxxx

\v

ASCII vertical tab (VT)

\000

Character with octal value 000

\xhh

Character with hex value hh


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python-4.文本,文本结合
下一篇:Java番外杂谈之每天扫的二维码你了解它内含的信息吗
相关文章

 发表评论

暂时没有评论,来抢沙发吧~