首先說明,在python中三個單雙引號並不是真正的注釋
>>> type("""abcde""") <class 'str'> >>> type('''abcd''') <class 'str'>
這樣可以看出三對單,雙引號是有數據類型的
三對單,雙引號的用法是定義的時候可以定義多行字符串
>>> a = """ ... a ... b ... c ... d ... """ >>> print (a) a b c d
一對單,雙引號也可以也可以定義多行字符串,但是要多麻煩有多麻煩
>>> b = "a\n"\ ... "b\n"\ ... "c\n"\ ... "d\n" >>> print(b) a b c d
當然三對單,雙引號也是可以使用在一行定義一行的字符串
那么單引號和雙引號有什么用.比如要輸入Let's me think
>>> str = 'Let\'s me think' >>> str "Let's me think"
如果使用單引號,那么就要使用轉譯符
>>> str = "Let's me think" >>> str "Let's me think"
雙引號就不需要
同樣的如果字符串里面含有雙引號比如:She said, "Hurry up".
>>> str = 'She said, "Hurry up".' >>> str 'She said, "Hurry up".'
使用單引號就不需要轉譯
>>> str = "She said, \"Hurry up\"." >>> str 'She said, "Hurry up".'
使用雙引號就需要轉譯