Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find "in" in the documentation

0 views
Skip to first unread message

tin...@isbd.co.uk

unread,
Mar 13, 2009, 5:01:52 PM3/13/09
to
I've had this trouble before, how do I find the details of how "in"
works in the documentation. E.g. the details of:-

if string in bigstring:

It gets a mention in the "if" section but not a lot.

--
Chris Green

Albert Hopkins

unread,
Mar 13, 2009, 5:26:00 PM3/13/09
to pytho...@python.org

>From http://docs.python.org/reference/expressions.html#in

The operators in and not in test for collection membership. x in
s evaluates to true if x is a member of the collection s, and
false otherwise. x not in s returns the negation of x in s. The
collection membership test has traditionally been bound to
sequences; an object is a member of a collection if the
collection is a sequence and contains an element equal to that
object. However, it make sense for many other object types to
support membership tests without being a sequence. In
particular, dictionaries (for keys) and sets support membership
testing.

For the list and tuple types, x in y is true if and only if
there exists an index i such that x == y[i] is true.

For the Unicode and string types, x in y is true if and only if
x is a substring of y. An equivalent test is y.find(x) != -1.
Note, x and y need not be the same type; consequently, u'ab' in
'abc' will return True. Empty strings are always considered to
be a substring of any other string, so "" in "abc" will return
True.

Changed in version 2.3: Previously, x was required to be a
string of length 1.

For user-defined classes which define the __contains__() method,
x in y is true if and only if y.__contains__(x) is true.

For user-defined classes which do not define __contains__() and
do define __getitem__(), x in y is true if and only if there is
a non-negative integer index i such that x == y[i], and all
lower integer indices do not raise IndexError exception. (If any
other exception is raised, it is as if in raised that
exception).


Benjamin Peterson

unread,
Mar 13, 2009, 5:29:57 PM3/13/09
to pytho...@python.org

Tim Chase

unread,
Mar 13, 2009, 5:40:36 PM3/13/09
to tin...@isbd.co.uk, pytho...@python.org
> I've had this trouble before, how do I find the details of how "in"
> works in the documentation. E.g. the details of:-
>
> if string in bigstring:

It's tough to find those generic keywords. It happens to be
documented a bit here:

http://docs.python.org/library/operator.html#operator.contains

http://docs.python.org/reference/expressions.html#id12

HTH,

-tkc

tin...@isbd.co.uk

unread,
Mar 13, 2009, 5:46:11 PM3/13/09
to
That's what I wanted, thanks, I maybe didn't stare hard enough at the
expressions section.

--
Chris Green

Piet van Oostrum

unread,
Mar 13, 2009, 6:14:12 PM3/13/09
to
>>>>> tin...@isbd.co.uk (t) wrote:

>t> I've had this trouble before, how do I find the details of how "in"
>t> works in the documentation. E.g. the details of:-

>t> if string in bigstring:

>t> It gets a mention in the "if" section but not a lot.

It is explained in The Python Language Reference, chapter Expressions,
section Comparisons. At least that's were it is in the 2.6 doc.
--
Piet van Oostrum <pi...@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi...@vanoostrum.org

Colin J. Williams

unread,
Mar 13, 2009, 7:46:58 PM3/13/09
to
Piet van Oostrum wrote:
>>>>>> tin...@isbd.co.uk (t) wrote:
>
>> t> I've had this trouble before, how do I find the details of how "in"
>> t> works in the documentation. E.g. the details of:-
>
>> t> if string in bigstring:
>
>> t> It gets a mention in the "if" section but not a lot.
>
> It is explained in The Python Language Reference, chapter Expressions,
> section Comparisons. At least that's were it is in the 2.6 doc.

Lots of people have been very helpful
but isn't the OP's real problem
that "in" is not included in the 2.6.1
Help index?

Colin W.

Gabriel Genellina

unread,
Mar 13, 2009, 10:42:23 PM3/13/09
to pytho...@python.org
En Fri, 13 Mar 2009 19:46:11 -0200, <tin...@isbd.co.uk> escribió:
> Albert Hopkins <mar...@letterboxes.org> wrote:
>> On Fri, 2009-03-13 at 21:01 +0000, tin...@isbd.co.uk wrote:
>> > I've had this trouble before, how do I find the details of how "in"
>> > works in the documentation. E.g. the details of:-
>> >
>> > if string in bigstring:
>>
> >From http://docs.python.org/reference/expressions.html#in

> That's what I wanted, thanks, I maybe didn't stare hard enough at the
> expressions section.

Also, from the interactive interpreter:

>>> help("in")
Comparisons
***********
[...]

Note that you have to use quotes around "in" because it's a keyword,
help(in) is invalid.

--
Gabriel Genellina

Tim Golden

unread,
Mar 14, 2009, 3:00:55 AM3/14/09
to pytho...@python.org

Well, this may not solve the OP's problem, but the current
(2.7a0) .chm file has a much better index for operators and
keywords. And "in" is in there. If you're interested in
comparing, there's a copy here:

http://timgolden.me.uk/python/downloads/snapshots/trunk/Python27a0.chm

TJG

jkn

unread,
Mar 14, 2009, 6:52:25 AM3/14/09
to
On Mar 14, 7:00 am, Tim Golden <m...@timgolden.me.uk> wrote:
> Well, this may not solve the OP's problem, but the current
> (2.7a0) .chm file has a much better index for operators and
> keywords. And "in" is in there. If you're interested in
> comparing, there's a copy here:
>
> http://timgolden.me.uk/python/downloads/snapshots/trunk/Python27a0.chm

Thanks for the link (should be a lowercase 'p' - python27a0.chm -
BTW). But having had a look at this file (under kchmviewer rather than
the Windows help viewer) ....

Ye Gods - it's almost unreadable. Not because of the content, but
because of the page style. I'm getting black text on a sort of slate
blue background. Is this the expected appearance?

Jon N

tin...@isbd.co.uk

unread,
Mar 14, 2009, 7:14:19 AM3/14/09
to
Yes, I think that is/was my problem. To find the information I had
to know that I should look in the Expressions chapter and while that
is (possibly) obvious for some things (+, -, AND, OR, etc.) it isn't
quite so obvious for "in".

--
Chris Green

Tim Golden

unread,
Mar 14, 2009, 7:59:28 AM3/14/09
to pytho...@python.org

Ummm. No. It uses the same css as the standard Python docs.
Frankly I think the contrast could be better, but it's
certainly readable.
Maybe some issue with the kchmviewer rendering? Might be
easier for non-Windows users to look at the dev docs online:

http://docs.python.org/dev/

since that's built from the same source / index. I find the
.chm far easier to search but the online docs are pretty good.

The (js-based) online search feature does work but, unfortunately,
is naive in its selection, so searching for "in" turns up any
page with the word "in" in it! The index page is rather better:

http://docs.python.org/dev/genindex-I.html


Hope that helps

TJG

Colin J. Williams

unread,
Mar 14, 2009, 12:08:24 PM3/14/09
to
Thanks. "in" is now in the index twice,
but I wasn't able to follow the links.

I trust that the improved docs will go
back to 2.6, unless 2.7 is almost ready.

Colin W

Tim Golden

unread,
Mar 14, 2009, 2:12:02 PM3/14/09
to pytho...@python.org


Worked for me. What was the problem?

TJG

0 new messages