I am confused about ' and "

Chris “Kwpolska” Warrick kwpolska at gmail.com
Thu Jul 10 14:25:39 EDT 2014


On Jul 10, 2014 7:53 PM, "fl" <rxjwg98 at gmail.com> wrote:
>
> Hi,
>
> It is still in the Regular expression operations concept, this link:
>
> has example using single quote mark: '
>
> https://docs.python.org/2/library/re.html#re.split
>
>
> While in this link:
>
> https://docs.python.org/3/howto/regex.html
>
>
> It gives table with quote: "
>
> Regular String  Raw string
> "ab*"   r"ab*"
> "\\\\section"   r"\\section"
> "\\w+\\s+\\1"   r"\w+\s+\1"
>
>
> and link:
>
> https://docs.python.org/2/library/re.html
>
>
> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
>
>
> Please tell me because I have looked it around for one hour about it.
>
> Thanks,
> --
> https://mail.python.org/mailman/listinfo/python-list

Both characters (' and ") are interchangeable, the only difference
being the one you need to escape if you want to use in a string:
"you're" vs 'you\'re', and the other way around.

Also, please read the Python tutorial[0] before getting into bigger
things, and please don’t mix documentation versions.  If you were to
read the tutorial, you’d quickly find out, that

> 3.1.2. Strings
>
> Besides numbers, Python can also manipulate strings, which can be
> expressed in several ways. They can be enclosed in single quotes
> ('...') or double quotes ("...") with the same result [2]. \ can be
> used to escape quotes.
>
> [snip]
>
> [2] Unlike other languages, special characters such as \n have the
> same meaning with both single ('...') and double ("...") quotes.
> The only difference between the two is that within single quotes
> you don’t need to escape "(but you have to escape \') and vice
> versa.


[0]: https://docs.python.org/2/tutorial/index.html

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense



More information about the Python-list mailing list