Home > Backend Development > Python Tutorial > The difference between single quotes, double quotes and triple quotes in Python

The difference between single quotes, double quotes and triple quotes in Python

高洛峰
Release: 2016-10-19 13:24:16
Original
1161 people have browsed it

In Python, strings can be enclosed in single quotes or double quotes. These two methods are equivalent. However, in PHP, some single quotes and double quotes are different. Although they represent strings, But 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 frequently. 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 have the same result.
Python triple quotes are 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, and the invisible characters such as n and t are not required. 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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template