Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Sequences Sequence Operations Sequence Operations Cheat Sheet

Inconsistent commands and syntax? Just memorize it ?

I noticed some of these python commands appear to be methods, some functions, and some I don't know.

For instance, given an array called my_array = [... .... ...] ...

To get the count of a content or item in an array, it is my_array.count(<content>) This appears to be a method of the array.

To get the length of the array however, it is len(my_array). len appears to be a function and the argument passed in is the array variable.

And then to delete index items from the array, it is del my_array[a:z] Is the del command in this case supposed to be a function, method of the array, or what ?

Just trying to make sense of how these python commands work, because otherwise I am just going to have to memorize or look up each time.

1 Answer

Disclaimer: I don't know Python. I just looked this stuff up, but I think this will answer your question. count() is a built-in method that you can use on lists/arrays (incidentally, you can use count() on strings as well). len() is a built-in function that returns the number of items in an object, or the number of characters in a string. del is a keyword used to delete objects. In Python everything is an object, so the del keyword can also be used to delete variables, lists, parts of a list, etc.

I got this information from W3 Schools: Python Reference and digging around.