Home >Backend Development >Python Tutorial >An introduction to the differences between single quotes, double quotes and triple quotes in Python
In pythonString can be enclosed in single quotes or double quotes. These two methods are equivalent, while in php single quotes and double quotes Some of the quotes are different. Although they represent strings, single quotes in PHP are parsed faster than double quotes.
If you need to represent a string object in python, there is no difference between single quotes and double quotes.
vice versa. This is why Python allows two methods. In practical applications, python single quotes and python double quotes are used more often. With these two representation methods, there is no need to use escape characters all the time.
For example, in python:
a = 'i love \'laowang python\''
print a
and
a = "i love 'laowang python'"
print a The result is the same.
python The form of triple quotes is used to enter multi-line text, which means that the content entered between the triple quotes will be retained as is. The single numbers and double quotes do not need to be escaped. Invisible characters such as \ Both n and \t will be retained. The advantage of this is that you can replace some multi-line text.
For example:
content = '''wwwfefefefefse%(name)s is
haha,he age is %(age)s'''
c = content % {'name':'pythoner ','age': '20'}
The result of print c is:
wwwfefefefefsepythoner is
haha,he age is 20
The above is the detailed content of An introduction to the differences between single quotes, double quotes and triple quotes in Python. For more information, please follow other related articles on the PHP Chinese website!