Python Intermediate - Alessio Vaccaro

61

Transcript of Python Intermediate - Alessio Vaccaro

Page 2: Python Intermediate - Alessio Vaccaro
Page 3: Python Intermediate - Alessio Vaccaro
Page 4: Python Intermediate - Alessio Vaccaro

set

Page 5: Python Intermediate - Alessio Vaccaro

list tuple set

set()

Page 6: Python Intermediate - Alessio Vaccaro

Sets

methods.intersection().union().difference()

Page 7: Python Intermediate - Alessio Vaccaro

set sets

methods .add() .update() .remove() .discard()

Page 8: Python Intermediate - Alessio Vaccaro

list comprehension lists

Page 9: Python Intermediate - Alessio Vaccaro

generators generator list next()

Page 10: Python Intermediate - Alessio Vaccaro

list list

Page 11: Python Intermediate - Alessio Vaccaro

list list

Page 12: Python Intermediate - Alessio Vaccaro
Page 13: Python Intermediate - Alessio Vaccaro
Page 14: Python Intermediate - Alessio Vaccaro

1

-

Page 15: Python Intermediate - Alessio Vaccaro

1

-

Page 16: Python Intermediate - Alessio Vaccaro
Page 17: Python Intermediate - Alessio Vaccaro

class

class attributes Classmethods class

1. Created a class in a saved script;2. Launched the script in the shell;

Page 18: Python Intermediate - Alessio Vaccaro

class

class attributes Classmethods class

I can access attributes of my class by using the proper syntax.

Page 19: Python Intermediate - Alessio Vaccaro

attributes

Page 20: Python Intermediate - Alessio Vaccaro

function class

Page 21: Python Intermediate - Alessio Vaccaro
Page 22: Python Intermediate - Alessio Vaccaro

class self.year None

Page 23: Python Intermediate - Alessio Vaccaro

__str__ special function

Page 24: Python Intermediate - Alessio Vaccaro

__str__ special function

Page 25: Python Intermediate - Alessio Vaccaro

special function __dict__

Page 26: Python Intermediate - Alessio Vaccaro

special functions

object.__str__(self)

object.__dict__(self)

object.__del__(self)

object.__hash__(self)

object.__repr__(self)

object.__bytes__(self)

object.__format__(self)

special functions

Page 27: Python Intermediate - Alessio Vaccaro
Page 28: Python Intermediate - Alessio Vaccaro

exceptions

Page 29: Python Intermediate - Alessio Vaccaro
Page 30: Python Intermediate - Alessio Vaccaro

handle exception try-except

Page 31: Python Intermediate - Alessio Vaccaro

handle exceptions

Page 32: Python Intermediate - Alessio Vaccaro
Page 33: Python Intermediate - Alessio Vaccaro

Lambdas functions anonymous functions Lambdasfunction

lambda

function

Page 34: Python Intermediate - Alessio Vaccaro

Lambdas attributes functions

Page 35: Python Intermediate - Alessio Vaccaro
Page 36: Python Intermediate - Alessio Vaccaro

Map function list

Page 37: Python Intermediate - Alessio Vaccaro

lists list

Page 38: Python Intermediate - Alessio Vaccaro

lists list list

sum len

Page 39: Python Intermediate - Alessio Vaccaro

lists list list

sum len

list comprehension

Page 40: Python Intermediate - Alessio Vaccaro

for map

sum len

Page 41: Python Intermediate - Alessio Vaccaro

for list comprehension map

• for while

As little as possible

Page 42: Python Intermediate - Alessio Vaccaro

Filter function

filter function numbers_list

lambda function module operator x%2

Page 43: Python Intermediate - Alessio Vaccaro

filter list strings

Page 44: Python Intermediate - Alessio Vaccaro
Page 45: Python Intermediate - Alessio Vaccaro

Python

Python AnacondaPython

libraries

piptcl/tk

other

Page 46: Python Intermediate - Alessio Vaccaro

libraries

piptcl/tk

other

> pip --version> pip 18.1

> pip install matplotlib> # to install something

> py -2 –m pip install matplotlib> # …selecting the right version of Py

> pip install --upgrade matplotlib> # to install and upgrade something

Page 47: Python Intermediate - Alessio Vaccaro

libraries

piptcl/tk

other

piptcl/tk

Page 48: Python Intermediate - Alessio Vaccaro

piptcl/tk

Page 49: Python Intermediate - Alessio Vaccaro

Python

Python

Page 50: Python Intermediate - Alessio Vaccaro

$ virtualenv –p /usr/bin/python3.6 «my_project»

$ source ‘path/to/env/bin/activate’

(my_project) user@localhost:~$

… do things in the environment…

(my_project) user@localhost:~$ deactivate

$

> virtualenv –p /usr/bin/python3.6 «my_project»

> ‘path/to/env/Script/activate’

(my_project) C://path/to/env >

… do things in the environment…

(my_project) C://path/to/env > deactivate

>

py -3 -m venv «my_project»

Page 51: Python Intermediate - Alessio Vaccaro
Page 52: Python Intermediate - Alessio Vaccaro
Page 53: Python Intermediate - Alessio Vaccaro

Page 54: Python Intermediate - Alessio Vaccaro

Repository

Working copy

Page 55: Python Intermediate - Alessio Vaccaro
Page 56: Python Intermediate - Alessio Vaccaro

Git

Page 57: Python Intermediate - Alessio Vaccaro
Page 58: Python Intermediate - Alessio Vaccaro

$ git config --global user.name "[my username]"

$ git config --global user.email "[my email address]"

Page 59: Python Intermediate - Alessio Vaccaro

$ git init# I initialized my folder as a local repository

$ git clone git://github.com/link_to_project.git# I copy inside my local repository a perfect copy of the remote repository

… hours of work on the code …

$ git add .# my code is now in the staging area ready to be confirmed and committed into my local repository

$ git commit -m ‘Added support to X functionality‘# I committed my code to the local repository

$ git push origin master# I uploaded the content of my local repository to the remote repository

Page 60: Python Intermediate - Alessio Vaccaro

git init

git clone [url]

git add [file]

git add .

git commit –m "[message]"

git push [alias] [branch]

git pull