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

** Operator

1 view
Skip to first unread message

Sathyaish

unread,
Mar 20, 2006, 12:39:06 AM3/20/06
to
In the example below from the python docs
(http://docs.python.org/tut/node7.html#SECTION007140000000000000000), I
am not able to understand the ** operator in the following expression:

>>> [(x, x**2) for x in vec]

I understand the list comprehension as a whole but have forgotten the
** operator's use. Can someone please guide me.

Sathyaish

unread,
Mar 20, 2006, 12:45:40 AM3/20/06
to
I tried it on the interpreter and it looks like it is the "to the power
of" operator symbol/function. Can you please point me to the formal
definition of this operator in the docs?

Alex Martelli

unread,
Mar 20, 2006, 1:08:20 AM3/20/06
to

Sathyaish

unread,
Mar 20, 2006, 1:28:30 AM3/20/06
to
Thanks, Alex.

Sathyaish

unread,
Mar 20, 2006, 1:30:03 AM3/20/06
to
Thanks, Alex.

Christoph Zwerschke

unread,
Mar 20, 2006, 6:53:09 AM3/20/06
to
Alex Martelli wrote:

> Sathyaish wrote:
>
>> I tried it on the interpreter and it looks like it is the "to the power
>> of" operator symbol/function. Can you please point me to the formal
>> definition of this operator in the docs?
>
> http://docs.python.org/ref/power.html

I think this should be also mentioned in the Built-In Functions section
of the Library Reference. Probably most users do not read the Language
Reference (since the main menu says it's "for language lawyers" and yes,
it is not really fun to read).

In the explanation about pow() at
http://docs.python.org/lib/built-in-funcs.html, the notation 10**2 is
suddenly used, without explaining that it is equivalent to pow(10,2). I
think this could be improved in the docs.

-- Christoph

Sathyaish

unread,
Mar 20, 2006, 7:31:30 AM3/20/06
to
Thanks very much for helping out, Christopher.

Ziga Seilnacht

unread,
Mar 20, 2006, 9:21:32 AM3/20/06
to

Christoph Zwerschke

unread,
Mar 20, 2006, 10:23:59 AM3/20/06
to
Ziga Seilnacht wrote:

> Christoph Zwerschke wrote:
>> In the explanation about pow() at
>> http://docs.python.org/lib/built-in-funcs.html, the notation 10**2 is
>> suddenly used, without explaining that it is equivalent to pow(10,2). I
>> think this could be improved in the docs.
>
> It is:
> http://docs.python.org/lib/typesnumeric.html

You're right, it's mentioned there in section 2.3.4, but the explanation
of pow() is already in section 2.1 prior to that.

So it would be nice if the paragraph explaining pow() would mention that
you can also write x**y for pow(x,y). And/or the example given in the
paragraph should say pow(10,2) instead of 10**2. Otherwise it's a bit
confusing for somebody who reads in chronological order and doesn't know
about the ** syntax (many other languages write x^y instead of x**y).

-- Christoph

Kent Johnson

unread,
Mar 20, 2006, 11:42:11 AM3/20/06
to
Christoph Zwerschke wrote:
>>http://docs.python.org/lib/typesnumeric.html
>
> You're right, it's mentioned there in section 2.3.4, but the explanation
> of pow() is already in section 2.1 prior to that.
>
> So it would be nice if the paragraph explaining pow() would mention that
> you can also write x**y for pow(x,y). And/or the example given in the
> paragraph should say pow(10,2) instead of 10**2. Otherwise it's a bit
> confusing for somebody who reads in chronological order and doesn't know
> about the ** syntax (many other languages write x^y instead of x**y).

The way to make this change happen is to submit a bug report with your
suggested change. See the link at the bottom of the above page to find
out how.

Kent

Christoph Zwerschke

unread,
Mar 20, 2006, 2:59:48 PM3/20/06
to
Kent Johnson wrote:
> The way to make this change happen is to submit a bug report with your
> suggested change. See the link at the bottom of the above page to find
> out how.

I know, but I wanted to see at least one person assenting before doing
so. Anyway, I took your words as assent and filed a bug report now ;-)

-- Christoph

Ron Adam

unread,
Mar 20, 2006, 3:39:18 PM3/20/06
to
Christoph Zwerschke wrote:
> Alex Martelli wrote:
>> Sathyaish wrote:
>>
>>> I tried it on the interpreter and it looks like it is the "to the power
>>> of" operator symbol/function. Can you please point me to the formal
>>> definition of this operator in the docs?
>>
>> http://docs.python.org/ref/power.html
>
> I think this should be also mentioned in the Built-In Functions section
> of the Library Reference. Probably most users do not read the Language
> Reference (since the main menu says it's "for language lawyers" and yes,
> it is not really fun to read).

I agree and think the "for language lawyers" should be changed to
something that encourages people to read it instead of encouraging them
to avoid it. Maybe:

"The Python language structure for everyone".

If it's hard to read and understand, then that can and should be fixed.

It probably should be moved to a position before the library reference
manual and after the tutorial. Looking over the language reference
manual will help in understanding the library reference manual I think.

Cheers,
Ron

Christoph Zwerschke

unread,
Mar 21, 2006, 3:40:28 AM3/21/06
to

... which was promptly rejected. Seems like the Gods of Python don't
want newbies to understand the manuals too easily, so they can have
their fun ranting why they did not RTFM, when they come here and ask
silly questions. ;-)

-- Christoph

Christoph Zwerschke

unread,
Mar 21, 2006, 4:29:16 AM3/21/06
to
Ron Adam wrote:
> I agree and think the "for language lawyers" should be changed to
> something that encourages people to read it instead of encouraging them
> to avoid it. Maybe:
>
> "The Python language structure for everyone".
>
> If it's hard to read and understand, then that can and should be fixed.

Hm, actually that was not my point. I think the writers of the Language
Reference already did a very good job. The precise and "authoritative"
language reference covering all the subtleties and special cases will
never be fun to read. You would rather learn the use of the keywords and
the basic rules and magic attributes of the language from a good
tutorial or handbook, and look up the Language Reference really
seldomly. You can program quite well in Python without ever having
looked into the official Language Reference. Newbies should not think
they need to read it in order to start programming.

However, it is different with the Lib Reference. This is used on a daily
basis, you will often look into it, Python users are accustomed to it,
and it should invite readers to really browse and read and learn more
about the power of the batteries included. My point was that since users
are more accustomed to and prefer to use the Lib reference as their
first source of information rather than the Language reference, it
should not be reluctant to mention some things which strictly speaking
belong to the Language Reference. In some cases, it can also point to
the Lanugage Reference for the details (and it does so already).

-- Christoph

Christoph Zwerschke

unread,
Mar 21, 2006, 11:24:33 AM3/21/06
to
Christoph Zwerschke wrote:
> Christoph Zwerschke wrote:
>> Kent Johnson wrote:
>>> The way to make this change happen is to submit a bug report with
>>> your suggested change. See the link at the bottom of the above page
>>> to find out how.
>>
>> I know, but I wanted to see at least one person assenting before doing
>> so. Anyway, I took your words as assent and filed a bug report now ;-)
>
> ... which was promptly rejected.

... but now it has been checked in by somebody else anyway. The Python
gods sometimes move in mysterious ways ;-)

-- Christoph

Terry Reedy

unread,
Mar 21, 2006, 12:58:36 PM3/21/06
to pytho...@python.org

>> ... which was promptly rejected.
>
> ... but now it has been checked in by somebody else anyway. The Python
> gods sometimes move in mysterious ways ;-)

The tracker item reviewers are people, including me, with different
knowledge, viewpoints and experiences, who sometimes disagree.


Georg Brandl

unread,
Mar 21, 2006, 6:36:08 PM3/21/06
to

Had I seen the tracker item and/or read this thread to the end before I made
that checkin, I probably wouldn't have made it... ;)

Georg

Christoph Zwerschke

unread,
Mar 22, 2006, 4:08:34 AM3/22/06
to
Georg Brandl wrote:
> Had I seen the tracker item and/or read this thread to the end before I made
> that checkin, I probably wouldn't have made it... ;)

But then we would have never known that the Python gods are only people ;-)

0 new messages