Python quotation marks

Source: Internet
Author: User

From: http://our2848884.blog.163.com/blog/static/146854834201192393137281/

Anyone who has learned Python should know that python contains single quotation marks, double quotation marks, and three quotation marks. But what are their differences?

Actually, I personally think that python is different from PHP, and there is no difference between single quotes and double quotes. Their main function is to avoid escape characters. For example:

>>> 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

As for the three quotation marks, the main purpose is to input multiple lines of text. That is to say, the content entered between the three quotation marks will be reserved as is, and the single and double quotation marks in the quotation marks do not need to be escaped, invisible characters, such as \ n and \ t, are retained. The advantage is that you can replace multiple lines of text.

C = ''' the Zen of Python, by Tim Peters beautiful is better than uugly. 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 shoshould never pass silently. unless explicitly silenced. in Face of ambiguity, refuse the temptation to guess. there shoshould 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 H Onking great idea -- let's do more of those! '''Print C will not stick to the print result. Let's go back and try it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.