3. python intro

  • View
    43

  • Download
    3

Embed Size (px)

DESCRIPTION

Week 2

Text of 3. python intro

  • 1. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines Many scientific libraries (SciPy, NumPy) Large community of scientists using it #1 programming language in universities Shell mode for experimentation
  • 2. Why Python? Easy to learn syntax
  • 3. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc.
  • 4. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines
  • 5. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines Many scientific libraries (SciPy, NumPy)
  • 6. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines Many scientific libraries (SciPy, NumPy) Large community of scientists using it
  • 7. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines Many scientific libraries (SciPy, NumPy) Large community of scientists using it #1 programming language in universities
  • 8. Why Python? Easy to learn syntax Built-in datatypes for lists, strings etc. Runs on many types of machines Many scientific libraries (SciPy, NumPy) Large community of scientists using it #1 programming language in universities Shell mode for experimentation
  • 9. Assignment uses = First assignment makes the var (not dim needed)
  • 10. Comparison uses ==
  • 11. Comparison uses == Print prints all datatypes (no toString() needed)
  • 12. Logical operators are words
  • 13. Multi assign
  • 14. Multi assign
  • 15. Datatypes
  • 16. Why?
  • 17. Why? Integers are the default
  • 18. and are both okay
  • 19. Whitespace
  • 20. This whitespace has meaning!
  • 21. Indentation marks a block No begin/end or {}
  • 22. Comments start with #
  • 23. Understanding Assignment
  • 24. What exactly happens is:
  • 25. What exactly happens is: Type: Integer Data: 5 memory
  • 26. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory
  • 27. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory
  • 28. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory
  • 29. Important: Python determines the type automatically Decides when to delete too (garbage collection) Type: Integer Data: 5 Name: a Ref: name list memory
  • 30. Important: Python determines the type automatically Decides when to delete too (garbage collection) Basic data types (int, float, string) are immutable Type: Integer Data: 5 Name: a Ref: name list memory
  • 31. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory
  • 32. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory Type: Integer Data: 6
  • 33. What exactly happens is: Type: Integer Data: 5 Name: a Ref: name list memory Type: Integer Data: 6
  • 34. What exactly happens is: Name: a Ref: name list memory Type: Integer Data: 6
  • 35. What exactly happens is: This is the garbage collector at work Name: a Ref: name list memory Type: Integer Data: 6
  • 36. Another example
  • 37. Another example Type: Integer Data: 6 Name: a Ref: name list memory
  • 38. Another example Type: Integer Data: 6 Name: a Ref: name list memory Name: x Ref:
  • 39. Another example Type: Integer Data: 6 Name: a Ref: name list memory Type: Integer Data: 10 Name: x Ref:
  • 40. Lists may contain a mix
  • 41. Lists may contain a mix Can even contain other lists
  • 42. Looking up items Counting starts at 0
  • 43. Looking up items Counting starts at 0 We can also count from the end!