len() function

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
How do you use the len() function? I tracked down a bug to a line where I reference the length of a list, so I tested this and it gave an error:

Code:
blockedCities = ["Test"]
testInteger = len(blockedCities)
if (testInteger == 1):
    ## Do nothing
What could the problem be? I think this is the correct syntax. I also tried blockedCities.len().
 
Thalassicus said:
How do you use the len() function? I tracked down a bug to a line where I reference the length of a list, so I tested this and it gave an error:

Code:
blockedCities = ["Test"]
testInteger = len(blockedCities)
if (testInteger == 1):
    ## Do nothing
What could the problem be? I think this is the correct syntax. I also tried blockedCities.len().

You didn't get a syntax problem with this? You can't just "do nothing" in a clause of an "if" statement. You have to at least "pass".

also len should return 1, but it might be strange because you only have a string in there, so I don't know what the behavior would be (I think it should still return 1, but, I'm not certain about it.)

Req
 
Back
Top Bottom