473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

** Operator

In the example below from the python docs
(http://docs.python.org/tut/node7.htm...0000000000000), 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.

Mar 20 '06 #1
17 1361
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?

Mar 20 '06 #2
Sathyaish <sa*******@gmail.com> 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
Alex
Mar 20 '06 #3
Thanks, Alex.

Mar 20 '06 #4
Thanks, Alex.

Mar 20 '06 #5
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
Mar 20 '06 #6
Thanks very much for helping out, Christopher.

Mar 20 '06 #7

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).

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


It is:
http://docs.python.org/lib/typesnumeric.html

Ziga

Mar 20 '06 #8
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
Mar 20 '06 #9
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
Mar 20 '06 #10
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
Mar 20 '06 #11
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

Mar 20 '06 #12
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. 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
Mar 21 '06 #13
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
Mar 21 '06 #14
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
Mar 21 '06 #15
... 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.


Mar 21 '06 #16
Terry Reedy wrote:
... 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.


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
Mar 21 '06 #17
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 ;-)
Mar 22 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
1
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
3
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD...
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
8
by: valerij | last post by:
Yes, hi How to write "operator +" and "operator =" functions in a class with a defined constructor? The following code demonstrates that I don't really understand how to do it... I think it has...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.