Discovering Python!

Thursday, July 13, 2006

Discover My Python Notes!

ActivePython is ActiveState's quality-assured, ready-to-install distribution of Python, available for AIX, HP-UX, Linux/x86 and Linux/x86_64 (new!), Mac OS X/PowerPC and Mac OS X/x86 (new!), Solaris SPARC and x86 (new!), and Windows/x86 and Windows/x64 (new!). As part of ActiveState's support for Python, we provide the ActivePython binary packages free to the Python community

Comments in Python start with the hash character, "#"

Complex numbers are also supported; imaginary numbers are written with a suffix of "j" or "J". Complex numbers with a nonzero real component are written as "(real+imagj)", or can be created with the "complex(real, imag)" function.

>>> 1j * 1J
(-1+0j)
>>> 1j * complex(0,1)
(-1+0j)
>>> 3+1j*3
(3+3j)
>>> (3+1j)*3
(9+3j)
>>> (1+2j)/(1+1j)
(1.5+0.5j)

Complex numbers are always represented as two floating point numbers, the real and imaginary part. To extract these parts from a complex number z, use z.real and z.imag.

>>> a=1.5+0.5j
>>> a.real
1.5
>>> a.imag
0.5

In interactive mode, the last printed expression is assigned to the variable _. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example:

0 Comments:

Post a Comment

<< Home