Basic Confusion

This is the place for queries that don't fit in any of the other categories.

Basic Confusion

Postby AlanD » Mon Jun 17, 2013 4:02 am

I am a newbie to Python, tho' an experienced coder.

In IDLE (Python 3.3) I type
Code: Select all
a=1+2j


dir(a) shows me that I have three built-in functions available, conjugate, real and imag.

Trial and error informs me that, whereas I need to use
Code: Select all
a.conjugate()
to avoid getting an error message, with the other two I need simply
Code: Select all
a.real
and
Code: Select all
a.imag
, and adding brackets results in an error message for each.

What logic am I missing here, and how do I learn which option to use for any built-in function simply by typing dir(a)?
AlanD
 
Posts: 1
Joined: Mon Jun 17, 2013 3:43 am
Location: Weybridge, England

Re: Basic Confusion

Postby micseydel » Mon Jun 17, 2013 4:20 am

You can use help() instead of dir() to get that information you wanted.

As for why it is that way, it's because the latter two are properties of the object that do not require any computation, whereas the first is something that has to be generated from the imaginary number rather than being part of what's stored for it. It's a subtle difference.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1355
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Basic Confusion

Postby ochichinyezaboombwa » Mon Jun 17, 2013 5:01 am

In other tongue, there are "data members" and "member functions (methods)". The former you use, the latter you call().
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests