Home » Python Programming » Python Programming – Week 5 – Lists / Hero Inventory

Python Programming – Week 5 – Lists / Hero Inventory

 

Notes:

  • List can be defined as a container that holds a number of other objects, in a given order. The list type implements the sequence protocol, and also allows you to add and remove objects from the sequence.
  • Lists use square brackets as containers.
    • Example:  x = [23,24,25]
    • Example:  x = [“clinton”,”bush”,”obama”]
  • When using Strings in list, use the single or double quotes.
  • Functionalities used in a list with examples, where x is the variable.
    • append – To add a value to a list permanently.
      • Example:  x.append = ()
    • sort – To sort a list alphabetically or numerically.
      • Example: x.sort = ()
    • insert – To place a value in the list into a specific location.
      • Example: x.insert = (2,99)  where 2 is the location, and 99 is the value.
    • remove – To remove a specific value from the list.
      • Example: x.remove = ()

 

 

Above is an example of using list in the Hero inventory.


Leave a comment

Your email address will not be published. Required fields are marked *