python引號作用

來源:互聯網
上載者:User

轉自:http://our2848884.blog.163.com/blog/static/146854834201192393137281/

  學過python的朋友應該都知道,python中包含單引號,雙引號和三引號。但是他們有什麼區別呢?

        其實,我個人感覺,python不同於php,其中的單引號和雙引號沒有區別。他們的主要作用就是盡量避免使用逸出字元。例如:

>>> a='I\'m a student.'>>> print aI'm a student.>>> a="I'm a student.">>> print aI'm a student.>>> b="\"Knuth\" is a genius.">>> print b"Knuth" is a genius.>>> b='"Knuth" is a genius'>>> print b"Knuth" is a genius

      至於三引號,其主要目的是用來輸入多行文本,也就是說在三引號之間輸入的內容將被原樣保留,之中的單號和雙引號不用轉義,其中的不可見字元比如\n和\t都會被保留,這樣的好處是你可以替換一些多行的文本。

c='''The Zen of Python, by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!''' print c         列印結果就不粘了,大家自己回去試一試吧。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.