Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PTW2015 Intro to Python

PTW2015 Intro to Python

Intro to Python, borrowed from Boston Python Workshop

sarahelizgray

April 23, 2015
Tweet

More Decks by sarahelizgray

Other Decks in Programming

Transcript

  1. About Me • Python and Ruby Lover • Software Engineer

    at • Regular Instructor at Girl Develop It Philly • Education Committee Member for Philly Python User Group
  2. About You :) • Your name • What brought you

    here • What you hope to learn
  3. The Plan 8:30 - 10:00 AM First Part 10:00 -

    10:15 AM Short Break 10:15 AM - Noon Second Part
  4. About Python -- Jargon Alert! • Invented in 1989 Guido

    Van Rossum • Duck Type Language • White Space Delimited • Derived from the C programming language • PEP8 • We are using Python 2, but 3 is on the near horizon • That’s it . . . jargon over :)
  5. The Problem I have two lists of names -- one

    list is all VPN usernames, one list is all the people who are no longer employed. I want to write a script to tell me which VPN accounts to revoke based on who is no longer employed.
  6. Building Blocks -- Getting Started ▪ math ▪ type() ▪

    variables ▪ strings ▪ booleans ▪ if/elif/else ▪ functions
  7. Building Blocks -- Lists ▪ purpose ▪ initialization ▪ len()

    review ▪ accessing elements ▪ adding elements ▪ changing elements ▪ slicing lists ▪ strings are like lists
  8. Building Blocks -- Loops and Flow Control ▪ for loops

    ▪ if statements inside for loops ▪ nested for loops ▪ range() ▪ while loops ▪ infinite loops ▪ if statements inside while loops ▪ break ▪ raw_input()
  9. Building Blocks -- Dictionaries ▪ purpose ▪ initialization ▪ accessing

    elements ▪ adding elements ▪ changing elements ▪ keys() and values()
  10. Building Blocks -- Modules ▪ purpose ▪ builtins ▪ imports

    ▪ import random ▪ random.randint ▪ random.choice
  11. Yay! Our Results! def sanitized_vpn(vpn_username): return vpn_name[4:] def sanitized_email(email_address) :

    return email_address.split('@')[0] #so we know what the list vals are grads = ['[email protected]', '[email protected]', 'jen@work. com'] vpn = ['vpn-tim', 'vpn-jen', 'vpn-clarence'] #nested loop concept to compare two lists def revoke_addresses(grads, vpn): revoke = [] for email_address in grads: username = sanitized_email(email_address) vpn_username = "vpn-" + username if vpn_username in vpn: print "found it " + vpn_username revoke.append(vpn_username) return revoke
  12. So, what now? • More Tutorials: ◦ https://www.python.org/about ◦ https://www.coursera.org/course/pythonlearn

    ◦ codingbat.com • Upcoming Classes: ◦ May 2/3 -- ◦ http://www.meetup.com/Girl-Develop-It- Philadelphia/events/221601923/ (almost sold out) ◦ May 29/30 -- PhillyPUG workshop TBA