python and you

47
PYTHON & YOU NETWORK WEEK 2015 WORKSHOP

Upload: sian-lerk-lau

Post on 06-Apr-2017

367 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Python and you

PYTHON& YOUNETWORK WEEK 2015 WORKSHOP

Page 2: Python and you

SIAN LERK LAUlinkedin.com/in/[email protected] | [email protected]

Software Engineer

Volunteer

Educator-in-Exile

Page 3: Python and you
Page 4: Python and you

https://twitter.com/OnApp - https://facebook.com/OnApp

Page 5: Python and you

WONDERFUL THINGS WE DO =)Python, Java, Ruby, Lua, Nginx, Wowza, Puppet, Vagrant, Docker, Debian, Cucumber, RabbitMQ, MariaDB, MongoDB, ELK, etc.

Page 6: Python and you

WE’RE HIRING!

SYSADMIN as integral role in managing and develop tools for our ecosystem

DEV as engineering role in creating bleeding edge applications for our ecosystem

YES, INTERNS TOO!

Page 7: Python and you

R UREHDYTO PYTHON*

Page 8: Python and you

FIVE DEADLY SINS

OF COMPUTER SCIENCE

Page 9: Python and you

I DO EVERYTHING EXCEPT

int main(void);NO. 5

Page 10: Python and you

I DO CODINGEXCEPTfor (;;);

NO. 4

Page 11: Python and you

I DO EVERYTHING EXCEPTMATHS

NO. 3

Page 12: Python and you

I DO NOTHINGEXCEPT

<NAME YOUR LANGUAGE>NO. 2

Page 13: Python and you

I DO NOTHINGEXCEPT

MY {WORK, STUDY}NO. 1

Page 14: Python and you

EVERCHANGINGINDUSTRY

OF COMPUTER SCIENCE

Page 15: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTLEARNING

NO. 5

Page 16: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTENGINEERING

NO. 4

Page 17: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTSPEED

NO. 3

Page 18: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTBUSINESS

NO. 2

Page 19: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTCOMMUNITY

NO. 1

Page 20: Python and you

SOFTWARE DEVELOPMENT

IS ABOUTYOU

NO. 0

Page 21: Python and you

DO.* WHY PYTHON* THE ENVIRONMENT* PYTHON 101* CONTROL STRUCTURES* A REAL PROGRAM

Page 22: Python and you

WHY* CODE IN PYTHON

Page 23: Python and you

EASY TO UNDERSTANDCONCISE SYNTAXMULTI-PURPOSE

STRENGTH OF PYTHON

Page 24: Python and you

GOOGLE-ABLE!WELL SUPPORTED LIBSFAST TO DELIVER

STRENGTH OF PYTHON

Page 25: Python and you

ENV*PYTHON ENVIRONMENT

Page 26: Python and you

# INSTALL PACKAGES$ sudo apt-get install python-pip python-virtualenv# SETUP ENVIRONMENT$ virtualenv workshop-env# ENABLE ENVIRONMENT$ source workshop-env/bin/activate

ENV* - ENVIRONMENT ISOLATION

Page 27: Python and you

101*PYTHON - DATA TYPES

Page 28: Python and you

# DECLARE-LESS TYPED>>> a = 1>>> print a1>>> type(a)<type 'int'>

101* - DATA TYPES

Page 29: Python and you

# MORE TYPES - '' and "">>> b = 'a'>>> c = 'abc'>>> d = "abc"# QUIZ: WHAT DATA TYPES ARE b, c and d?>>> type(b)>>> type(c)>>> type(d)

101* - DATA TYPES

Page 30: Python and you

# MORE TYPES# bool, NoneType, float, long>>> e = True>>> f = False>>> g = None>>> h = 1.0>>> i = 1L# QUIZ: WHAT IS None?

101* - DATA TYPES

Page 31: Python and you

101*PYTHON - COLLECTIONS

Page 32: Python and you

# COLLECTION 1: LIST>>> a = [1, 2, 3]>>> b = list()>>> b.append(1)>>> b.append(2)>>> b.append(3)# QUIZ: How do we retrieve the value?# QUIZ: Is a and b same?

101* - DATA TYPES

Page 33: Python and you

# SAME - EQUALITY or IDENTITY?>>> a == bTrue>>> a is bFalse

# QUIZ: WHAT IS THE DIFF # BETWEEN == AND is

101* - DATA TYPES

Page 34: Python and you

# COLLECTION 2 - TUPLE>>> c = (1, 2, 3)>>> d = 1, 2, 3

# QUIZ: SO AGAIN, IS c SAME with d?

101* - DATA TYPES

Page 35: Python and you

# COLLECTION 3: dict>>> e = {1: 11, 2: 22}>>> e[1]>>> e[2]

# QUIZ: IS THIS AN array?# QUIZ: MUST THE key BE int?

101* - DATA TYPES

Page 36: Python and you

# COLLECTION 4: set>>> f = set()>>> f.add(1)>>> f.add(2)>>> f.add(3)

# QUIZ: WHAT IS THE DIFF # BETWEEN list AND set?

101* - DATA TYPES

Page 37: Python and you

101*PYTHON - CONTROL STRUCTURES

Page 38: Python and you

101* - DATA TYPES

# if, else, elif>>> a = 2>>> if a == 1:... print "hello"... elif a == 2:... print "world"

>>>

Page 39: Python and you

101* - DATA TYPES

# if, else, elif CONTINUES>>> a = 1>>> if a == 1:... print "hello"... else:... print "world"

>>>

Page 40: Python and you

101* - DATA TYPES

# for LOOP>>> for i in [1, 2, 3]:... print i

>>> for j in range(1,3):... print j

# QUIZ: WHAT DO YOU SEE WHEN print j

Page 41: Python and you

101* - DATA TYPES

# for LOOP>>> for i in (1, 2, 3):... print i

>>> for k,v in {1: 11, 2: 22}.iteritems():... print k, v

# QUIZ: WHAT DO YOU SEE WHEN print k, v

Page 42: Python and you

101* - DATA TYPES

# list comprehension>>> a = [1,2,3,4,5]>>> b = [i+1 for i in a]

# QUIZ: WHAT IS THE VALUE OF b?

Page 43: Python and you

101* - DATA TYPES

# list comprehension>>> a = [1,2,3,4,5]>>> b = [i for i in a if i % 2 == 0]

# QUIZ: WHAT IS THE VALUE OF b?

Page 44: Python and you

PROG*A REAL PROGRAM, NOW

Page 45: Python and you

# CREATE AN EXECUTABLE FILE$ touch calculator.py$ chmod +x calculator.py

# QUIZ: MUST YOU END THE FILENAME WITH # A FILE EXTENSION?

PROG* - A REAL PROGRAM

Page 46: Python and you

# IMPROVISE IT$ vim calculator.py$ nano calculator.py<or, use your favourite text editor>

# RUN IT$ ./calculator.py

PROG* - A REAL PROGRAM

Page 47: Python and you

Q&A*ASK ME ANYTHING