Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74319 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2014-07-10 10:01 -0700 |
| Last post | 2014-07-10 20:25 +0200 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
I am confused about ' and " fl <rxjwg98@gmail.com> - 2014-07-10 10:01 -0700
Re: I am confused about ' and " John Gordon <gordon@panix.com> - 2014-07-10 17:16 +0000
Re: I am confused about ' and " Chris Angelico <rosuav@gmail.com> - 2014-07-11 03:57 +1000
Re: I am confused about ' and " Joel Goldstick <joel.goldstick@gmail.com> - 2014-07-10 14:12 -0400
Re: I am confused about ' and " Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-07-10 20:25 +0200
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2014-07-10 10:01 -0700 |
| Subject | I am confused about ' and " |
| Message-ID | <cfa25009-b200-4fcc-beb7-83634546cd20@googlegroups.com> |
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,
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2014-07-10 17:16 +0000 |
| Message-ID | <lpmhp2$f1u$1@reader1.panix.com> |
| In reply to | #74319 |
In <cfa25009-b200-4fcc-beb7-83634546cd20@googlegroups.com> fl <rxjwg98@gmail.com> writes:
> Please tell me because I have looked it around for one hour about it.
There is no difference between ' and " when used to enclose strings, with
one exception: a double-quoted string can contain single-quotes without the
need to escape them with a backslash, and vice-versa.
For example:
string2 = "It's a beautiful day in the neighboorhood."
string1 = 'He said to me, "Hello Thomas."'
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-07-11 03:57 +1000 |
| Message-ID | <mailman.11740.1405015040.18130.python-list@python.org> |
| In reply to | #74319 |
On Fri, Jul 11, 2014 at 3:01 AM, fl <rxjwg98@gmail.com> wrote: > Please tell me because I have looked it around for one hour about it. > It's high time you started at the beginning, rather than trying to learn regexps without understanding Python. https://docs.python.org/3/tutorial/index.html Start there. You will much better understand Python, and you won't have to ask for help with these sorts of things. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2014-07-10 14:12 -0400 |
| Message-ID | <mailman.11741.1405015938.18130.python-list@python.org> |
| In reply to | #74319 |
On Thu, Jul 10, 2014 at 1:01 PM, fl <rxjwg98@gmail.com> wrote: > Hi, > > It is still in the Regular expression operations concept, this link: You must have missed my comment about quote and double quote. In python you can write a string using either. Just make sure if you start with double quote, you must end with double quote. Before tackling regular expressions, go to the python tutorial and learn about strings. > > 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 -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
|---|---|
| Date | 2014-07-10 20:25 +0200 |
| Message-ID | <mailman.11742.1405016747.18130.python-list@python.org> |
| In reply to | #74319 |
On Jul 10, 2014 7:53 PM, "fl" <rxjwg98@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web