Upgrade to PRO for Only $50/Yearβ€”Limited-Time Offer! πŸ”₯

Python 101 Day 2

Avatar for Anna Anna
November 18, 2017
61

Python 101 DayΒ 2

Avatar for Anna

Anna

November 18, 2017
Tweet

Transcript

  1. What is Python? β–ͺ Interpreted Language – don't have to

    compile it β–ͺ Multi-paradigm: OOP (no access specifiers), Functional and others... β–ͺ Guido van Rossum ("Benevolent Dictator For Life") β–ͺ Dynamic typing – Don't have to specify data types for variables β–ͺ Pythonic code and Zen of Python β–ͺ Cython, PyPy β–ͺ Indentation β–ͺ Built in garbage collector
  2. Built in types β–ͺ Immutable built-in types of Python –

    Numbers – Strings – Tuples β–ͺ Mutable built-in types of Python – List – Dictionaries – Sets
  3. Assignments = β–ͺ x = 2 β–ͺ C/C++: "typed variable

    name x receives a copy of numeric value 2". The (right-hand) value is copied into an allocated storage location for which the (left-hand) variable name is the symbolic address. β–ͺ Python: "(generic) name x receives a reference to a separate, dynamically allocated object of numeric (int) type of value 2."
  4. Let's do some maths! β–ͺ // vs / β–ͺ **

    β–ͺ Results of a division is always a float β–ͺ 1 is True 0 is False β–ͺ Is 2 True?
  5. If else β–ͺ x if c else y β–ͺ elif

    β–ͺ Pass β–ͺ No switches
  6. Lists β–ͺ append, pop, remove, insert, index, extend β–ͺ Slicing

    β–ͺ :: β–ͺ list[start:end:step] β–ͺ join β–ͺ List comprehensions β–ͺ [:] deep copy β–ͺ in
  7. for β–ͺ Calls iter() on object β–ͺ range – values

    on demand for x in range(0, 10, 1): print(x)
  8. Any and All β–ͺ Any returns True if any one

    item in the iterable is True β–ͺ All returns True if all the items in the iterable is True
  9. We do have arrays... β–ͺ Array β–ͺ Have to be

    of a specific type β–ͺ https://www.python.org/doc/essays/list2str/
  10. Dictionary β–ͺ What keys are hashable? β–ͺ get(), setdefault() β–ͺ

    Dict comprehensions β–ͺ {x: x+2 for x in range(1,100)}
  11. def β–ͺ Functions are first class objects – I can

    assign them to variables β–ͺ Pass by value vs pass by reference??? β–ͺ *args – Variable number of args β–ͺ **kwargs – Variable number of keyword args
  12. Magic methods β–ͺ Overloaded operators in C++ β–ͺ What if

    I want to compare two objects with < and > ? β–ͺ object.__lt__(self, other)
  13. Maps and filters β–ͺ map(function, data) β–ͺ filter(function, data) β–ͺ

    Reduce - from functools import reduce – You need two args in the lambda
  14. Try except β–ͺ Else – Runs only if no exceptions

    were raised β–ͺ Finally – Run everytime β–ͺ raise
  15. Sets β–ͺ Elements of set have to be immutable β–ͺ

    No order β–ͺ & | - >= <= β–ͺ {x for x in range(1,100)}
  16. class β–ͺ First class objects β–ͺ Self - myobject.method(arg1, arg2)

    => MyClass.method(myobject, arg1, arg2) β–ͺ Hidden variables – Not really hidden β–ͺ Supports Multiple inheritance β–ͺ Isinstance β–ͺ issubclass