Creating an Array: Difference between revisions

list methods are not related to creating lists
(list methods are not related to creating lists)
Line 348:
 
List are mutable arrays. You can put anything into a list, including other lists.
 
empty = []
numbers = [1, 2, 3, 4, 5]
Line 355 ⟶ 356:
evens = range(0,10,2) # Optional arguments to range() can specify start, stop, and step
squares = [ x * x for x in range(100) ] # List comprehension expressions can create lists
digits.insert(0, digits.pop()) # List objects support various methods,
# .pop() removes and returns last item, .insert(index, item) does what you'd expect
 
Tuples are immutable arrays. Note hat tuples are defined by the "," - the parenthesis are optional:
Anonymous user