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

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,Python3)