In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the difference between single quotation marks, double quotation marks and triple quotation marks in Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between Python's single quotation marks, double quotation marks and triple quotation marks?"
When writing Python scripts, use quotation marks to define the contents of the string; in Python, you can use three kinds of quotation marks, namely, single quotation marks, double quotation marks, three quotation marks, etc., all of which are used to define strings, is there any difference in using them?
Let's start with single quotation marks and double quotation marks.
Both single and double quotation marks are used to define a string:
In fact, there is no difference between the use of single quotes and double quotes!
So why does Python use these two methods to define strings, which is not redundant? In fact, in terms of defining strings, single and double quotes complement each other:
If the original string contains single quotation marks, you can use double quotation marks to define
If the original string contains double quotation marks, you can use single quotation marks to define
Look at the example:
You can also use escape characters to escape single or double quotation marks in a string, but it is cumbersome to write (even more troublesome if there are a lot of quotes in the string) and becomes less readable.
You will find that this is why Python supports double quotation marks and single quotation marks to define strings, and also reflects the flexibility and ease of use of Python!
Tell me about the three quotes.
Here three quotation marks indicate: three pairs of single quotes or three pairs of double quotes.
# three pairs of single quotes form 'string...''' # three pairs of double quotes form' "" string... ""
Three quotes are also defined strings, but the frequency of use of three quotes is not as high as single and double quotes. It is more efficient and elegant to use three quotation marks on some special occasions!
Write multiline document comments:
Very intuitive! It is also troublesome to use "#" to write multiline comments!
Define multiline strings:
The string contained in three quotes can be composed of multiple lines and can be wrapped directly without the use of "\ n", and there is no need to escape the string with single or double quotation marks.
It is very simple and intuitive to write! It would be crazy to try to do it in single or double quotation marks!
Conclusion
In different scenarios, use different forms of quotation marks to define strings, which fully reflects the flexibility and ease of use of Python!
At this point, I believe you have a deeper understanding of "what is the difference between Python's single quotes, double quotes and triple quotes". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.