Python vs. Perl, which is better to learn?

Andrew Dalke dalke at dalkescientific.com
Wed May 1 05:26:48 EDT 2002


Alex:
> >>> a35=re.compile('^a{3,5}$')
>   ...
> >>> print a35.match('aaaaa')
> <_sre.SRE_Match object at 0x8186960>
> >>> print a35.match('aaaaaa')
> None
> >>>
>
> Python re's imitate Perl's closely enough that this is a rather unPythonic
> arrangement -- the upper bound is *included* (Python's ranges, slices etc
> have lower-bound-included, upper-bound-excluded...).

But it isn't a range, it's a repeat count.  Otherwise people would
also expect

  ^a{0}

to match "" because that contains 0 "a"s.  As such, it's much more
similar to
  "a" * 3 == "aaa"
  "a" * 5 == "aaaaa"

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list