+ 1
Is this an array or list?
When you have a variable like : Leds = [4,17,22,11] Is this an array or list?
9 Answers
+ 13
By default, Python does not support arrays (as they are understood in other languages) using lists instead.
Python's numpy module introduces arrays treated like matrices (or tensors in general). You can do linear algebraic operations in them as if they were matrices, indeed.
+ 5
Good luck with the Pi, by the way ;)
+ 4
It's a list in python.
+ 4
Basically in this case, you have a range consisting of numbers 0,1,2,3,4 and 5. It's not an array but here i is acting as the index number for accessing values from list leds.
+ 2
thanks
0
thanks guys
0
and how do i explain ; for i in range(0,6)
GpIo.output(leds[i], false)
0
the [ i] is related to an array?
0
[i] in leds[i] is not an array or similar, it is an index, many types of lists use indexing: strings, lists, tuples, dictionaries.
By more complex answer each type of object has a class.
To make an object indexable, you need to define atleast 2 functions called magic methods, __init__ and __index__.
__init__ is ran when you use the class name as function and it is used to create objects.
__index__ is ran when you use the index [i].
When you use leds[i] you pass 2 arguments to the __index__ method, the list object leds and the index i.
This also allows programmer to make new list types.
You often have 2 ways to create any builtin list types in python.
Such as lists have:
[x, y, z]
list([x, y, z])
Because there was already created a list in list(), it is not best way to make lists, but it can be used to convert other types to lists. Even those that can't be indexed.