Learn to Code

《笨办法学Python3》练习十:那是什么?

2019-03-01  本文已影响0人  雨开Ame

练习代码

tabby_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(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)

Study Drills

  1. Memorize all the escape sequences by putting them on flash cards.
  2. Use ''' (triple-single-quote) instead. Can you see why you might use that instead of """?
  3. Combine escape sequences and format strings to create a more complex format.

补充

常用转义字符
上一篇 下一篇

猜你喜欢

热点阅读