Final summary from my notes, 2022:

2+2 # this wont print bc there is more code here
print(2+3) # this will bc you tell it to
2-2 # last obj in cell will print w/o error code
  • Booleans are a TYPE in python: TRUE (=1) OR FALSE (=0)
    • useful in if statements
    • useful in database mgmt
  • COmparsions: <, >, <=, >=, !=, ==
  • Membership: in, not in
  • Logic: and, or, not
  • built in py functions:
    • print(), round(), sum(), len(), type()
    • convert one type to another: list(), str(), float()
  • EVERYTHING IS AN OBJECT :
    • obj have attribute
    • obj have methods (FUNCTIONS that work on the object)
    • dot syntax: .() with paren
    • . without paren
  • obj types
    • str, int, floats
    • DATA TYPES: list, dict, set
Type Name Example Description
list [1, 2, 3] Ordered collection
tuple (1, 2, 3) Immutable ordered collection
dict {'a':1, 'b':2, 'c':3} Unordered (key,value) mapping
set {1, 2, 3} Unordered collection of unique values

Hello everyone! Before class:¶

  1. In GH Desktop: Fetch/pull your class notes repo and the lecture repo.
  2. Copy these files from the textbook repo into your class notes/exercises folder:
    • ledatascifi-2022/handouts/Python exercises.ipynb
    • ledatascifi-2022/content/01/06_python.ipynb
  3. Suggested: Open the module notes file on one side of your Jupyterlab screen and the two files above on the other side of your screen.

Hopefully this goes better than Chrissy Teigen's experience with Py:

First things first¶

  • Someone ask me an assignment question
  • Any questions on the github exercises or jupyterlab exercises?
  • Any other questions
  • Announcements on classmates-2022 posts: You should be receiving them as emails. Let me/Julio know ASAP if not!
  • Priya's Announcement (next slide)

wibconf.PNG

This week - learning by doing¶

Homework tips

Cover much of 1.7.2's python essentials:

  • arithmetic (*)
  • logic
  • common functions
  • common python data structures (*)
  • everything is an object / methods
  • flow control: for loops, if, and indentation (ooooh)

And debugging, good practices, and maybe how to gitignore files.

Homework tips - due Sunday at 8pm¶

After this assignment, we can start considering much more interesting challenges!

Big points:

  1. No time extensions
  2. Make sure you read ALL the instructions/instructions.md file! Everything there is graded, as this assignment covers the basic skills we use throughout

Tips:

  1. Obey the 15 minute rule on syntax errors!
  2. https://github.com/orgs/LeDataSciFi/teams/classmates-2022/discussions/4
  3. google "csv pandas" and see chapter 2.4 in the textbook
  4. Chapter 1.7 in the textbook for the other python problems

Python Essentials¶

  • Next two days: basics needed for ASGN 1 and getting you coding
    • Type and run everything you can in your notes!!!
  • Quick and dirty = we can't cover "everything"
    • But this + the website has ~ enough ~ for A1
    • Also: Me + TA + @classmates-2022

Comments¶

Remember to use comments! In fact, over use them in the beginning.

They help you, future you, and others understand what

  • A particular line of code is doing
  • What blocks of code are doing
  • The idea behind why you wrote the code as you did (big picture)

Else, you'll find yourself in this photo soon:

badcode.jpg

Comments¶

Remember to use comments! In fact, over use them in the beginning.

They help you, future you, and others understand what

  • A particular line of code is doing
  • What blocks of code are doing
  • The idea behind why you wrote the code as you did (big picture)

More (advanced) thoughts in Chapter 2.7

Guided discussion + practice¶

We will run parts of the textbook file in our open notes file.

  • Arithmetic
    • Q1: How many full hours are in 7643 minutes?
    • Q2: If a 1 dollar stock appreciates at 10% a year, how much is it after 7 years?
  • Booleans, comparisons, logic, membership, and PEMDAS/parenthesis
  • Common built-in functions
  • Everything is an object / Methods
  • Data structures (next slide): lists, tuple, dict, sets
  • Then practice

Built in data structures¶

TIP: Copy this table from the textbook into your Module notes!

Listed from most commonly used to least:

Type Name Example Description
list [1, 2, 3] Ordered collection
dict {'a':1, 'b':2, 'c':3} Unordered (key,value) mapping
set {1, 2, 3} Unordered collection of unique values
tuple (1, 2, 3) Immutable ordered collection

Working with list objects¶

L=[8, 5, 6, 3, 7]

  • "Zero indexed": L[0] returns 8, L[1] returns 5
  • Can access from the end: L[-1] returns 7, L[-2] returns 3
  • Lots of built in functions: len, sort, reversed, max, min, sum, count, append, extend,...
    • Prof demo: Show the py reference in Jlab, search for "data structures"
    • Prof demo: Find this outside JLab
  • Can access "slices": L[<start at index> : <go till index>]
    • L[0:3] and L[:3] return [8,5,6]
    • L[-3:] returns [6,3,7]
  • Let's work on python exercises.ipynb now!

Summary¶

  • You're writing code!
  • You've written and solved your first bugs!
  • 15 minute rule

Shutting down¶

TIP: This is also how you save assignment work to github!

And at the end of each working session (i.e. class or doing homework),

  1. Restart your kernel and rerun your code
  2. save all open code files (in j-lab)
  3. optional: close j-lab (and the terminal running it)
  4. commit and push your Class Notes repo (in GH-D)
  5. open the GitHub.com version of the repo, and click on the file(s) you just updated to see the changes reflected online!