Slide 1

Slide 1 text

Olá! Eu sou Yan Orestes Produtor de conteúdo na 1 @yanorestes

Slide 2

Slide 2 text

Python 2 X Python 3 Qual versão aprender?

Slide 3

Slide 3 text

Python 2 X Python 3 Qual versão aprender? Em qual versão programar?

Slide 4

Slide 4 text

Ué e a retrocompatibilidade?

Slide 5

Slide 5 text

retrocompatibilidade?

Slide 6

Slide 6 text

falhas de design Python 2

Slide 7

Slide 7 text

falhas de design Python 3

Slide 8

Slide 8 text

8 Python 2 ou Python 3? Entendendo (finalmente) as diferenças entre as duas versões principais da linguagem

Slide 9

Slide 9 text

Mudanças sutis 1. 9

Slide 10

Slide 10 text

Python 2 >>> print 'Hello, world!' Hello, world!

Slide 11

Slide 11 text

>>> print 'Hello, world!' File "", line 1 print 'Hello, world!' ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, world!')? Python 3

Slide 12

Slide 12 text

Python 2 e Python 3 >>> print('Hello, world!') Hello, world!

Slide 13

Slide 13 text

raw_input X input

Slide 14

Slide 14 text

raw_input X input Python 2 Python 3

Slide 15

Slide 15 text

Python 2 >>> input() Oi! Traceback (most recent call last): File "", line 1, in File "", line 1 Oi! ^ SyntaxError: unexpected EOF while parsing

Slide 16

Slide 16 text

Lazy evaluation 2. 16

Slide 17

Slide 17 text

range função X classe

Slide 18

Slide 18 text

range função X classe lista instância Python 2 Python 3

Slide 19

Slide 19 text

Python 2 >>> range(10**10) Traceback (most recent call last): File "", line 1, in MemoryError

Slide 20

Slide 20 text

Python 3 >>> range(10000**10000) range(0,1000000000000000000000 00000000000000000000000000000 00000000000000000000000000000 00000000000000000000000000000 00000000000000000000000000000 00000000000000000000000000…)

Slide 21

Slide 21 text

Python 2 Mas e o xrange?

Slide 22

Slide 22 text

Python 2 >>> range(10**10) xrange(0,10000000000)

Slide 23

Slide 23 text

Python 2 >>> xrange(10000**10000) Traceback (most recent call last): File "", line 1, in OverflowError: Python int too large to convert to C long

Slide 24

Slide 24 text

Números 3. 24

Slide 25

Slide 25 text

números grandes long X int

Slide 26

Slide 26 text

Python 2 >>> sys.maxint 9223372036854775807 >>> sys.maxint + 1 9223372036854775808L >>> type(sys.maxint + 1)

Slide 27

Slide 27 text

Python 3 >>> sys.maxsize 9223372036854775807 >>> sys.maxsize + 1 9223372036854775808 >>> type(sys.maxsize + 1)

Slide 28

Slide 28 text

divisão de int Python 2 X Python 3 int float

Slide 29

Slide 29 text

Python 2 >>> 4/2 2 >>> 3/2 1

Slide 30

Slide 30 text

Python 3 >>> 4/2 2.0 >>> 3/2 1.5

Slide 31

Slide 31 text

Python 2 e Python 3 >>> 3//2 1

Slide 32

Slide 32 text

"Texto" 4. 32

Slide 33

Slide 33 text

Python 2 >>> type('Hello, world!') >>> type(u'Hello, world!')

Slide 34

Slide 34 text

Python 2 str unicode bytes texto

Slide 35

Slide 35 text

Python 2 >>> len('Ā') 2 >>> len(u'Ā') 1

Slide 36

Slide 36 text

Python 3 bytes str bytes texto

Slide 37

Slide 37 text

Python 3 >>> type('Hello, world!') >>> type(u'Hello, world!') >>> type(b'Hello, world!')

Slide 38

Slide 38 text

Python 3 >>> π = 3.14 >>> π 3.14

Slide 39

Slide 39 text

Identificador de GIFs def is_gif(filename): with open(filename, 'rb') as f: identificador = f.read(6) return identificador == 'GIF89a'

Slide 40

Slide 40 text

Identificador de GIFs Python 2 True Python 3 False

Slide 41

Slide 41 text

Identificador de GIFs def is_gif(filename): with open(filename, 'rb') as f: identificador = f.read(6) return identificador == b'GIF89a'

Slide 42

Slide 42 text

Comparação 5. 42 ● == != ● > < ● >= <=

Slide 43

Slide 43 text

43 cmp e __cmp__ -1 (<), 0 (==), 1 (>)

Slide 44

Slide 44 text

44 cmp e __cmp__ -1 (<), 0 (==), 1 (>)

Slide 45

Slide 45 text

45 Python 2 todos os objetos são comparáveis ordinalmente entre si

Slide 46

Slide 46 text

46 Python 2 todos os objetos são comparáveis ordinalmente entre si ??????????

Slide 47

Slide 47 text

47 Python 2 >>> foo = MinhaClasse() >>> foo < 'a' True >>> foo < 1 True >>> foo < [] True

Slide 48

Slide 48 text

48 Python 2 >>> 999999999 < 'a' True >>> 999999999 < [] True >>> 999999999.99 < [] True

Slide 49

Slide 49 text

49 Python 2 >>> ' ' > [] True >>> 'str' > 'list' True

Slide 50

Slide 50 text

50 Python 3 >>> ' ' > [] Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'str' and 'list'

Slide 51

Slide 51 text

Indentação 6. 51

Slide 52

Slide 52 text

52 Python 3 >>> while True: ... print('oi') ... print('tchau') File "", line 3 print('tchau') ^ TabError: inconsistent use of tabs and spaces in indentation

Slide 53

Slide 53 text

53 Qual versão aprender? (e qual ensinar?)

Slide 54

Slide 54 text

54 Para qual versão programar?

Slide 55

Slide 55 text

55 2014 - Python 2 78% X 22% Python 3

Slide 56

Slide 56 text

56 2014 - Python 2 78% X 22% Python 3 2016 - Python 2 60% X 40% Python 3

Slide 57

Slide 57 text

57 2014 - Python 2 78% X 22% Python 3 2016 - Python 2 60% X 40% Python 3 2017 - Python 2 25% X 75% Python 3

Slide 58

Slide 58 text

58 Tornando seu programa mais compatível

Slide 59

Slide 59 text

Python 2 e Python 3 >>> print('Hello, world!') Hello, world!

Slide 60

Slide 60 text

from sys import version_info if version_info.major == 3: input() else: raw_input()

Slide 61

Slide 61 text

from sys import version_info if version_info.major == 3: input() else: raw_input()

Slide 62

Slide 62 text

from sys import version_info if version_info.major > 2: input() else: raw_input()

Slide 63

Slide 63 text

from sys import version_info if version_info.major == 3: input() else: raw_input()

Slide 64

Slide 64 text

Às vezes é mais fácil pedir desculpas do que pedir permissão 64 - Grace Hopper

Slide 65

Slide 65 text

try: raw_input('Digite seu nome: ') except NameError: input('Digite seu nome: ')

Slide 66

Slide 66 text

try: raw_input('Digite seu nome: ') except NameError: input('Digite seu nome: ')

Slide 67

Slide 67 text

Muito obrigado! Alguma pergunta? Você pode falar comigo em ▪ @yanorestes ▪ [email protected] 67

Slide 68

Slide 68 text

Agradecimentos especiais ▪ Python Brasil ▪ Alura/Caelum ▪ Casa do Código (PythonBrasil&CasadoCodigo) 68 15%

Slide 69

Slide 69 text

Design da apresentação Essa apresentação usa as seguintes fontes: ▪ Títulos: Work sans bold ▪ Corpo: Work sans light ▪ Código: Arial com formatação do tohtml.com Você pode baixar as fontes nessa página https://github.com/weiweihuanghuang/Work-Sans/tree/master/fonts/desktop 69 Layout dos slides e ícones por SlidesCarnival