当前位置 : 主页 > 编程语言 > python >

python-5.原样输出,转义字符

来源:互联网 收集:自由互联 发布时间:2022-07-07
exercise 9 python换行符,\n,tab制表符\t 多行文本原样输出.不解析变量,但是换行符号,转义字符仍旧生效,与php里面的nowdoc类似.三个单引号与三个双引号作用一样. # Here's some new strange stuff, re

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.\n
Even 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


上一篇:python-4.文本,文本结合
下一篇:没有了
网友评论