lists and tuples
play

Lists and Tuples Ali Taheri Sharif University of Technology Spring - PowerPoint PPT Presentation

Fu Fundamentals of Pr Programming (Py Python) Lists and Tuples Ali Taheri Sharif University of Technology Spring 2019 Outline 1. List Basics 2. List Operations 3. Lists are Mutable 4. Iterating over Lists 5. List Methods 6. Matrices


  1. Fu Fundamentals of Pr Programming (Py Python) Lists and Tuples Ali Taheri Sharif University of Technology Spring 2019

  2. Outline 1. List Basics 2. List Operations 3. Lists are Mutable 4. Iterating over Lists 5. List Methods 6. Matrices 7. Tuples 2 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  3. List Basics List is an ordered collection of values ◦ Values are called elements or items Defining Lists: 3 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  4. List Basics Accessing Elements: 4 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  5. List Operations Checking membership: ◦ Using in operator 5 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  6. List Operations The + operator concatenates lists: The * operator repeats a list: 6 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  7. List Operations Slicing: 7 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  8. List Operations Deletion: 8 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  9. Lists are Mutable List items can be changed ◦ We can change items using index operator ◦ With the slice operator we can update a whole sub-list at once: 9 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  10. Lists are Mutable ◦ We can also remove elements from a list by assigning an empty list: ◦ And we can add elements to a list by squeezing them into an empty slice at the desired location: 10 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  11. Iteration over Lists Just like strings: 11 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  12. List Methods Access built-in methods using dot operator: 12 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  13. List Methods Other useful methods: 13 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  14. Matrices Nested lists are often used to represent matrices 14 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  15. Tuples Group any number of items into single values Very similar to lists ◦ Except they are immutable! 15 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

  16. Tuples Assignment ◦ Packing: ◦ Unpacking: 16 Spring 2019 ALI TAHERI - FUNDAMENTALS OF PROGRAMMING [PYTHON]

Recommend


More recommend