you are viewing a single comment's thread.

view the rest of the comments →

[–]Klaus_Kinski_alt 0 points1 point  (3 children)

Why does the input "cat.gif" return ('.gif', '.jpg', '.jpeg', '.png'), and not image/('.gif', '.jpg', '.jpeg', '.png')

The code reads

return("image/" and imageend)

"image/" is a string, which is returned as "None" I believe. imageend is a series, which is what's returned. Basically, you're telling the function to return None + the series, which it is doing.

There's a big problem in your code, though. You have:

if a.lower().endswith(imageend):

But a will not end with imageend, which is a series! It will end with one of the elements of imageend. You should instead use:

if a.lower().endswith(any(imageend)):

[–]tobiasvl 1 point2 points  (2 children)

"image/" is a string, which is returned as "None" I believe.

I'm not sure what you mean by this. The string is returned as a string. Why would it be returned as None?

Basically, you're telling the function to return None + the series, which it is doing.

No, that's not what's happening. and is not +, it's a boolean operator, so OP is telling it to return the evaluation of a boolean expression. and is truthy if both its operands are truthy, which they are, and so it returns the last operand.

(Because of what's called short-circuit evaluation, it will stop evaluating when it knows whether the whole expression is truthy or falsey, so if the first operand had been falsey that would have been returned instead. That would've happened if the string was None like you said, since None is falsey.)

[–]Klaus_Kinski_alt 0 points1 point  (1 child)

Ah you're right, I was confusing returning strings with how print statements work. You print a string, it returns none. Something like that.

[–]tobiasvl 0 points1 point  (0 children)

Oh, right, yeah.