1 of 18

Python Essentials II�Module 3 - 3.4.1.1 ~ 3.4.1.12

Cisco Networking Academy Introduction

1

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

2 of 18

Licensing & Attribution

Open Source Philosophy - I have come to realize that I’m really not competing with other teachers. Maybe I have some local competition, but in reality, if a student is not coming to my class or my school, then I’m not competing with other teachers in any way… If you work more than a District away, then we really are not competitors. Let's Share... Collaborate... Help each other... I, and you, may have sweat blood and tears developing a lesson plan, a lab, or presentation… There is an ENORMOUS unpaid value there… I get that… I don’t begrudge teachers who are trying to sell their collateral… I’m just saying that is not what I’m going to do. But that is my plan. I’m going to share virtually everything I develop. Join Me!!! See More

CC BY-NC-SA 4.0

https://creativecommons.org/licenses/by-nc-sa/4.0/

https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode

GNU Public License & EUPL (European Union Public Licence)

Any included or linked Programming Code Is licensed under GNU General Public License v3.0 & and / or licensed under EUPL 1.2 or later

See the Appendix for Additional Licensing & Attribution Information

2

Please maintain this slide with any

modifications you make

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

3 of 18

Resources & Materials Needed

  • PC, Laptop or Other device to access sites & applications specified by your Instructor
  • Access to the Cisco Networking Academy �Python Esentials class

3

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

4 of 18

👉 Try This:

  • Browser: You can use a web based Browser IDE like Replit.com, PythonTutor or Trinket.
  • Installed Python IDLE: If you installed Python open an IDLE window

4

print("Hisssssssssss")

Try This 👉

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

5 of 18

Sections Covered In This Lesson

3.4.1.1 - Why do we need lists?

3.4.1.2 - Indexing lists

3.4.1.3 - Accessing list content

3.4.1.4 - Removing elements from a list

3.4.1.5 - Negative indices are legal

3.4.1.6 - Lab

3.4.1.7 - Functions vs. methods

3.4.1.8/9 - Adding elements to a list

3.4.1.10 - Making use of lists

3.4.1.11 - Lists in action

3.4.1.12 - Lab

5

Try This 👉

Work all the code examples in the sections

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

6 of 18

Key Concepts & Topics...

  • Multi-value variables, e.g. numbers [10,5,7,2,1]
    • list may have different types
    • convention: list always numbered starting from zero
    • the above example is a list of scalars
  • Selecting an element from a list is called indexing
  • Assigning a new value 111 to first element: numbers[0]=111
  • Accessing list. Entire list, e.g. print (numbers) or particular element , e.g. print(numbers[0]) =111; print(numbers)= [111,5,7,2,1]
  • Length of a list is the len() function,.e.g. len(numbers) is 5
  • Removing from list, e.g. del numbers[1] removes element1
  • You can not access an element which does not exist
  • Negative indices are legal. numbers[-1] is the last element, e.g. 1; numbers[-2] is the 2nd last one, e.g. 2; numbers[-3], is 7 etc.

6

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

7 of 18

Key Concepts & Topics...

  • A function doesn't belong to any data - it gets data, it may create new data and it (generally) produces a result.
    • functions take an argument, does something, and returns a result
    • typical function: result = function(arg)
  • A method is a specific kind of function - it behaves like a function and looks like a function, but differs in the way in which it acts, and in its invocation style.
    • A method is like a function but is also able to change the state of a selected entity
    • typical method: result= data.method(arg)
  • A method is owned by the data it works for, while a function is owned by the whole code.

7

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

8 of 18

Key Concepts & Topics...

  • Adding elements to a list
    • new element glued to end of list: list=append(value)
    • this is a method named append(). Takes argument's value and puts it at the end of the list which owns the method.
    • The list's length then increases by one.
    • insert() method adds new element at any place in the list
      • It takes two arguments. Position and the actual element
      • e.g. numbers.insert(0, 222) inserts 222 in position 0
  • List can start empty. This is done with an empty pair of square brackets
  • the for instruction specifies the variable used to browse the list
    • e.g. for i in my_list
  • Python offers a more convenient way of doing the swap without using a third variable
    • e.g. variable_1, variable_2 = variable_2, variable_1

8

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

9 of 18

Your Take-Away From These Sections

  • List is a type of data used to store multiple objects
    • ordered and mutable collection
    • separated by comma between square brackets
  • Lists can be indexed and updated
  • Lists can be nested
  • List elements and lists can be deleted
  • Lists can be iterated using for loop
  • len() function to check list’s length
  • function invocation: result = function(arg)
  • method invocation: result = data.method(arg)

9

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

10 of 18

Can You Answer These Questions?

What is the output?lst = [1,2,3,4,5]�lst.insert (1,6)�del lst[0]�lst.append(1)�print(lst)�

What is the output?lst = []�del lst�print(lst)

What is the output?lst = [1, [2,3],4]�print(lst[1])�print(len(lst))

10

"Mastery" means you can describe why these topics and concepts are important. Can you explain and discuss these ideas? As you read and work the code examples pay special attention to these ideas.

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

11 of 18

Thank You…

Questions?

11

If you are in one of my classes, you can probably send / post questions in:

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

12 of 18

Reference Slides

12

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

13 of 18

Education Standards

  • California's 2013 CTE Standards
  • Next Generation Science Standards
  • California Math Common Core Standards
  • California English Common Core Standards
  • California History-Social Science Standards
  • California English Language Development Standards
  • Next Generation Science Standards (1)
  • California's 2013 CTE Standards (2)
  • Related Instructional Objectives (SWBAT...)

13

13

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

14 of 18

Quiz Answers

14

  1. What is the output?�lst = [1,2,3,4,5]�lst.insert (1,6)�del lst[0]�lst.append(1)�print(lst)��answer: [6,2,3,4,5,1]�
  2. lst = []�del lst�print (lst)��answer: NameError: name ‘lst’ is not defined�
  3. lst = [1, [2,3],4]�print(lst[1])�print(len(lst))��answer: [2,3]� 3

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

15 of 18

Appendix

15

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

16 of 18

Appendix : Primary Sources & Attribution for Material Used

16

Please maintain this slide with any modifications you make

  • <Add Your Logo and Attribution here>
  • Much of this interpretation is primarily the Intellectual Property of Jim Burnham, Top STEAM Clown, at STEAMClown.org
  • My best attempt to properly attribute, or reference any other sources or work I have used are listed below. This presentation and content is distributed under the Creative Commons License and the The programming code found in this presentation or linked to on my Github site is distributed under the GPL and EUPL:

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

17 of 18

Image Reference & Sources

17

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

18 of 18

What To Fix, Add, Or Change

Presentation Planning:

18

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions