Difference between len() and array.length

can you help me with it? thanks

They are both methods of returning a count of something. This something can be the count of characters in a string, or the number of elements in an array. Which one you use is dependent on the coding language you are using. For example:

// Using the JS method
var enemies = hero.findEnemies();
var enemyCount = enemies.length; 
# Using the PY method
enemies = hero.findEnemies()
enemyCount = len(enemies)
# Getting the length (character count) in PY
sample = "12345678"
sampleLen = len(sample) # returns 8
3 Likes

hi thanks for the help.

But I saw array.length in python as well, it’s also usable in python language?

1 Like

Actually, it is! I had never used .length, being used to the len() method, but it does work. I tried this as a test:

testArray = [item1]
testLen1 = testArray.length
testLen2 = len(testArray) + 1
hero.say(testLen1)
hero.say(testLen2)
# hero says '1' and then '2'
3 Likes

Thank you! mmmmmmmmmmmmmmmm

1 Like