3. Python - Lists
Lists:
listexample = ["hello", 35, 'A']
listexample[0] // returns "hello"
listexample[-1] // returns 'A' at the end
Slicing:
listexample[0:3] // 0,1, and 2 index
listexample[:3] // same as above
listexample[1:-1] // exclude first and last
listexample[1:] // skip first and go to end of list
Functions:
len(listhere) // length of list
sorted(listhere) // sort ABC
sum(listhere) // sums list
max(listhere) // max
min(listhere) // min
List Methods:
listname.append("NEWITEM")
listname.pop() // returns and removes last item of list
listname.index("ITEMTOSEARCH") // returns index of item
"ITEM" in listname // returns false or true if item is in list or not
Tuples: // like list but immutable and uses parenthesis instead
tupletest = (1,2,2,2)
Comments
Post a Comment