assert type([]) == type(())
Josh Holland
jrh at joshh.co.uk
Sat Jan 2 11:40:14 EST 2010
On 2010-01-02, VanceE <vnewel at invalid.invalid> wrote:
> for x in []:
> assert type(x) == type(())
>
> I expected an AssertionError but get no errors at all.
> Any explaination?
That loop never runs. It immediately raises a StopIteration and the body
is never executed.
cf.
for x in []:
print "In loop body"
You won't see anything printed.
OTOH, look at this one:
for x in [[]]: # a list containing an empty list
assert type(x) == type(())
That will raise the AssertionError as expected.
--
Josh "dutchie" Holland <jrh at joshh.co.uk>
http://joshh.co.uk
http://twitter.com/jshholland
http://identi.ca/jshholland
More information about the Python-list
mailing list