1 of 19

Python Essentials II�Module 3 - 3.6.1.1 ~ 3.6.1.9

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 19

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 19

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 19

👉 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 19

Sections Covered In This Lesson

3.6.1.1 - The inner life of lists

3.6.1.2 - Powerful slices

3.6.1.3 - Slices - negative indices

3.6.1.4/5 - Slices continued

3.6.1.6 - The in and not in operators

3.6.1.6/7/8 - Lists - some simple programs

3.6.1.9 - 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 19

Key Concepts & Topics...

  • The assignment: list_2=list_1 copies the name of the arrays not its contents. BUT, the two names point to the same location in memory
  • Make a brand new copy of a list, use :
    • list_1=[1] #contains one element, 1�list_2=list_1[:] # list_2 is a brand new copy�list_1[0]=2 #list_1 element0 is now 2�print(list_2) #list_2 retains a copy of list_1, output=1
  • slice: my_list[start:end]
    • makes a new target list from start to end-1
    • my_list=[10,8,6,4,2]new_list=my_list[1:3] # start from element 1 to element 3-1�print (new_list) #output [8,6]
  • slice-negative indices
    • my_list=[10,8,6,4,2]new_list=my_list[1:-1] # one back from end of list�print (new_list) # output is [8,6,4]�new_list=my_list[1:-2] # two back from end of list�print (new_list) # output is [8,6]

6

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

7 of 19

Key Concepts & Topics...

  • If start specifies elements outside, then [ ], e.g.new_list=my_list[-1,1]
  • If you omit start, then assume index is 0. e.g. my_list[:end] # [0:end]
  • If you omit end, the assume slice ends at element with index len(my_list)
    • my_list=[10,8,6,4,2]new_list=my_list[3:] #assume end=5�print (new_list) # output= [4,2]
  • As stated before, omitting start and end makes a copy of the whole list
  • Deleting slices, e.g. my_list [10,8,6,4,2]
    • delete the whole list, e.g. del my_list[:]
    • delete slice, e.g.�del my_list[1:3] #delete from element 1 to element 3-1(elements 1 and 2)�print (my_list) # output = [10,4,2]
    • del will delete the list itself, not the content�del my_list�print (my_list) # you get a run time error because the list doesn’t exist
  • The in and not in operators
    • checks to see if given elements are in or not in: True or False

7

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

8 of 19

Your Take-Away From These Sections

  • If you have a list 11, the following assignment: 12=11 makes variable 11 and 12 point to the same list in memory.
  • If you want to copy a list of part of the list, you can perform slicing
  • You can use negative indices
  • when you slice, start and end parameters are optional in list[start:end]
  • You can delete slices using del instruction
  • Test items if they exist in a list or not using in and not in

8

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

9 of 19

Can You Answer These Questions?

What is the output?list_1 = ["A", "B", "C"]

list_2 = list_1

list_3 = list_2

del list_1[0]

del list_2[0]

print(list_3)

What is the output?list_1 = ["A", "B", "C"]�list_2 = list_1�list_3 = list_2�del list_1[0]�del list_2�print(list_3)�print(list_2)

What is the output?list_1 = ["A", "B", "C"]

list_2 = list_1

list_3 = list_2

del list_1[0]

del list_2[:]

print(list_3)

9

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

10 of 19

Can You Answer These Questions?

What is the output?list_1 = ["A", "B", "C"]�list_2 = list_1[:]�list_3 = list_2[:]�del list_1[0]�del list_2[0]�print(list_3)

Insert in or not in, in place of ??? to get expected result

my_list = [1, 2, "in", True, "ABC"]

print(1 ??? my_list) # outputs True

print("A" ??? my_list) # outputs True

print(3 ??? my_list) # outputs True

print(False ??? my_list) # outputs False

10

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

11 of 19

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 19

Reference Slides

12

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

13 of 19

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 19

Quiz Answers

14

  1. Outputs?�list_1 = ["A", "B", "C"]

list_2 = list_1� list_3 = list_2� del list_1[0]� del list_2[0]� print(list_3)��Answer: [‘C’]�

2. � list_1 = ["A", "B", "C"]� list_2 = list_1� list_3 = list_2� del list_1[0]� del list_2� print(list_3)� print(list_2)

Answer: ['B', 'C']� list_2 is undefined��3.� list_1 = ["A", "B", "C"]� list_2 = list_1� list_3 = list_2� del list_1[0]� del list_2[:]� print(list_3)

Answer: []

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

15 of 19

Quiz Answers

15

4. Outputs?�list_1 = ["A", "B", "C"]�list_2 = list_1[:]�list_3 = list_2[:]�del list_1[0]�del list_2[0]�print(list_3)

Answer: ['A', 'B', 'C'] # because list_3 is an independent copy of original not touched

5. Insert in or not in, in place of ??? to get expected result��my_list = [1, 2, "in", True, "ABC"]

print(1 ??? my_list) # outputs True

print("A" ??? my_list) # outputs True

print(3 ??? my_list) # outputs True

print(False ??? my_list) # outputs False

Answer: �print(1 in my_list) # outputs True

print("A" not in my_list) # outputs True

print(3 not in my_list) # outputs True

print(False in my_list) # outputs False

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

16 of 19

Appendix

16

STEAM Clown ™ Productions

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

17 of 19

Appendix : Primary Sources & Attribution for Material Used

17

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

18 of 19

Image Reference & Sources

18

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions

19 of 19

What To Fix, Add, Or Change

Presentation Planning:

19

© Copyright - STEAM Clown TM

Creative Commons Licenses - BY-NC-SA 4.0

STEAM Clown TM Productions