simple perl program in python gives errors
steve at holdenweb.com
Mon Jan 30 12:07:05 EST 2006
squash at peoriadesignweb.com wrote:
> I am a little annoyed at why such a simple program in Perl is causing
> so much difficulty for python, i.e:
> $a += 200000 * 140000;
> print $a;
Yes, an annoying feature of the Python interpreter is that it doesn't
always interpret Perl correctly.
You will find, though, that
print 200000 * 140000
works quite well in both languages (with or without the trailing
Variables in Python don't need a $ or @ to indicate whether they are
scalar or structured - that depends on their value.
a = 0
a += 200000 * 140000
should also work quite well. Note the first assignment is needed because
while there's no need to declare variables, you cannot assume a value
until they have been assigned one (in Pythonic jargon "bound to a value").
What does "+=" mean in Perl, by the way? Does it just assume $a is zero
if it isn't currently existent?
happily-forgotten-perl-ly y'rs - steve
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list