Equivalent in Python?
Tim Hammerquist
tim at vegeta.ath.cx
Tue Apr 30 17:38:50 EDT 2002
Philip Swartzleonard graced us by uttering:
> James J. Besemer || Mon 29 Apr 2002 03:11:25p:
>
>>
>> Vincent Foley wrote:
>>
>>> What's the Python equivalient of Perl's "a"++; ?
>>
>> You can't get there from here.
>>
>> I.e. there is no practical equivalant.
>>
>> Including it would allow deadly side-effects within an expression and
>> thus would percipitate the end of the world, or at least mankind.
>>
>> Regards
>>
>> --jb
>
> But if you just want to increment something, use 'foo+=1'. Exactly the
> same, except one more character and only works on a line of it's own
> (avoiding above said doom... man pointer-walking funcitons in C are
> nuts with that... =)
Well, yes and no. The type being incremented is a string, not an
int. For example:
# perl
$a = 10; $a++;
$b = "m"; $b++;
$c = "az"; $c++;
print $a, "\n"; -> 11
print $b, "\n"; -> "n"
print $c, "\n"; -> "ba"
Many question the usefulness of this perl feature, but it's come in
handy many times when dealing with alphanumerics with a limited
fieldwidth (Win32 FAT16/32 filenames, to name one).
I don't believe there's a built-in equivalent in python, but it's always
possible to write it.
HTH
Tim Hammerquist
--
Wow, I'm being shot at from both sides. That means I *must* be right. :-)
-- Larry Wall in <199710211959.MAA18990 at wall.org>
More information about the Python-list
mailing list