Advertisement
lubattillah

lists

Jun 11th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. """
  2. Discusion on Lists
  3. """
  4. -a list is created by using [], e.g. l=[1,"joe",[2,3,4]]
  5. -can contain a list inside it
  6. -an element in a list is referred by an index and always starts from 0
  7. -an empty list is created by assigning empty [] to a list, say empty_list=[]
  8. -accessing list items, suppose we need to access first item from l above, it will be l[0] and the last element is obtained by l[-1]
  9. -list common methods are append for adding an item at the end i.e list.append(value), insert for adding an item in any specified position i.e. list.insert(position,value), remove for removing items by either a value using list.remove(value) or list.pop(position)
  10.  
  11. Other examples of data to be stored in a list
  12. -Number of courses taken by a students in a certain class
  13. -Months
  14. -Employees donating their pensions in a certain social security fund etc.
  15.  
  16. When to introduce lists to your learners and how would you do so
  17. -I can introduce list if I intend to teach them how to store more data at a time.
  18. -I would do this by establishing examples of this that might need to be stored in the list such as list of months in a year, list of patients attended heart clinic last month, etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement