Slide 1

Slide 1 text

Python as a first language Yoav Ram June 2018

Slide 2

Slide 2 text

Python is interpreted & dynamic Interpreter is great for novice programmers Dynamic type system allows fast prototyping

Slide 3

Slide 3 text

Python is high-level Design emphasizes code readability “looks like pseudocode”

Slide 4

Slide 4 text

Python design principles • Aims for simplicity and generality • Semantic whitespaces (newlines, indentation) • English keywords (and, or, not, in, is, as) • Operator overloading (”hello “ + “world”) There should be one—and preferably only one— obvious way to do it Wikipedia

Slide 5

Slide 5 text

Example: Hello World! Java public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World!”); } } Python print(“Hello World!”) Complex: classes, accessibility, arrays, functions, static, return type (void!), namespaces, standard output… and compilation. Simple. Try in online interpreter : tiny.cc/PyHelloWorl

Slide 6

Slide 6 text

Example: simple program def f2c(f=None): if f is None: f = input(“Enter F degrees: “) f = float(f) return (f – 32) * 5 / 9 def c2f(c=None): if c is None: c = input(”Enter C degrees: “) c = float(c) return 9 / 5 * c + 32 tiny.cc/PyF2C

Slide 7

Slide 7 text

Python is pluralist Cross-platform Multiple programming paradigms

Slide 8

Slide 8 text

Programming paradigms • Object-oriented programming (C++, Java, C#) • Imperative programming (C) • Functional programming (Haskell) • Event driven & async programming (JavaScript) – Co-routines (async) or callbacks (tornado) Wikipedia

Slide 9

Slide 9 text

OOP class Rectangle(Shape): def __init__(self, lower_left, upper_right): self.ll = lower_left self.ur = upper_right def area(self): width = self.ur.x – self.ll.x height = self.ur.y – self.ll.y return width * height def __contains__(self, point): return ( self.ll.x < point.x < self.ur.x and self.ll.y < point.y < self.ur.y )

Slide 10

Slide 10 text

Almost everything is an object • strings, lists, dictionaries, tuples, functions, classes, types • Strong polymorphism • Duck typing

Slide 11

Slide 11 text

Functional programming generators n = len(numbers) mean = sum(numbers) / n devs = (x – mean for x in numbers) squared_devs = (x*x for x in numbers) var = sum(squared_devs) / n std = var**0.5 def make_power(a): def power(x): return x**a return power square = make_power(2) square(4) # => 16 closure

Slide 12

Slide 12 text

Python is “batteries included” Large standard libraries Easy to install many 3rd party libraries Domain specific distributions

Slide 13

Slide 13 text

Large standard library • Files: zip, gzip, json, csv, tempfile, linecache, xml, wave • db: sqlite3, dbm • Network: socket, ssl, async • Web: urllib, http.server, email, ftplib, cgi, html, uu • Crypto: hashlib, hmac, secrets • Software: logging, unittest, mock, doctest, curses, sched, queue, getpass, gettext, tk,pdb, profiler • Concurrency: threading, multiprocessing, async, futures, subprocess • collections, functools, itertools… Python docs

Slide 14

Slide 14 text

Many new libraries released every month During 2015, > 1,500 new packages released every month to PyPI. See more stats at PyGarden/stats.

Slide 15

Slide 15 text

Python is free Gratis: Free as in Beer Libre: Free as in Speech GitHub | Mailing lists

Slide 16

Slide 16 text

Python is open Open-source software Community-based development Managed by non-profit Python Software Foundation

Slide 17

Slide 17 text

History of Python • Developed in 1989-91 by Guido van Rossum in the Netherlands • Python 2.0 released Oct 2000 • Many major new features: – cycle-detecting garbage collector – support for Unicode – shift to transparent and community-backed development • Python 3.0 released Dec 2008 – major backwards-incompatible release – many of major features backported to Python 2.6 and 2.7 • Python 3.5 released Sep 2015 • Python 3.7 beta available, final expected June 2018

Slide 18

Slide 18 text

Python is cool Jupyter notebooks, online interpreters, code on your phone, Raspberry Pi

Slide 19

Slide 19 text

Python is fast enough Easy to wrap more C Easy to parallelize Numerical packages implemented in C Cython: transcoder to C Numba: JIT compiler Benchmark Game | NumFocus Benchmarks

Slide 20

Slide 20 text

Python for data science & scientific computing With libraries like NumPy, SciPy, Matplotlib, IPython/Jupyter, Scikit-image, Scikit-learn, and more Replacing MATLAB Pushed by Google, Microsoft, others

Slide 21

Slide 21 text

Python is popular and has a great community

Slide 22

Slide 22 text

Easy to find help on the Internet • Python is 6th most popular tag on StackOverflow stackoverflow.com/tags, May 2018

Slide 23

Slide 23 text

Active community • 3rd most active repositories on GitHub after Java (incl. Android) and JavaScript (incl. node.js) • As of May 2018 • See breakdown at githut

Slide 24

Slide 24 text

Demand for Python programmers is high

Slide 25

Slide 25 text

Coding Dojo

Slide 26

Slide 26 text

Python is widely-used In academia In industry In education As Wikipedia examples…

Slide 27

Slide 27 text

Python is used at Google, Rackspace, Microsoft, Intel, Walt Disney, MailChimp, twilio, Bank of America, Facebook, Instagram, HP, Linkedin, Elastic, Mozilla, YouTube, ILM, Thawte, CERN, Yahoo!, NASA, Trac, Civilization IV, reddit, LucasFilms, D-Link, Phillips, AstraZeneca, Applied Materials, KLA-Tencor, Nova, Lam Research, Marvell https://us.pycon.org/2016/sponsors/ https://www.python.org/about/quotes/ https://en.wikipedia.org/wiki/Python_%28programming_language%29#Use https://en.wikipedia.org/wiki/List_of_Python_software https://www.python.org/about/success/

Slide 28

Slide 28 text

First language in US CS departments 1. Carnegie-Mellon: Python, C 2. MIT: Python 3. Stanford: Python, Java, JavaScript 4. Berkeley: Python 5. U Illinois UC: Python, Java, MATLAB, C 6. Cornell: Python, MATLAB 7. U Wash: Python, Java 8. Princeton: Java • Olin: Python Phillip Gou @ CACM

Slide 29

Slide 29 text

Phillip Gou @ CACM, 2014

Slide 30

Slide 30 text

First language in Israeli departments TAU: Python HUJI: Python Technion: C BGU: Java BIU: C Haifa: C Open U: Java 2017-2018

Slide 31

Slide 31 text

But why Python? Guido was reading some Monty Python's Flying Circus sketches and thought Python would be a cool name Python 2 FAQ

Slide 32

Slide 32 text

Encyclopædia Britannica Online Thanks for listening 32 [email protected] @yoavram www.yoavram.com