introdução à linguagem python

Post on 25-Jun-2015

1.841 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Telas -- bastante baseadas nas do Álvaro (http://alvarojusten.blogspot.com/) -- utilizadas no minicurso de Python realizado na PythOnCampus do dia 6 de junho de 2009, na UVA de Cabo Frio.

TRANSCRIPT

Introdução à linguagem PythonAlex Tercete Matos

6 de junho de 2009

Antes de começar. . .

PythOnCampus Introdução à linguagem Python – 2 / 28

Quem sou eu?

PythOnCampus Introdução à linguagem Python – 3 / 28

• CEFET/RJ

− Engenharia de Controle e Automação

• Chemtech

− Desenvolvimento de software

• Software Livre

− GNU/Linux− Python− etc.

Quem sou eu?

PythOnCampus Introdução à linguagem Python – 3 / 28

• CEFET/RJ

− Engenharia de Controle e Automação

• Chemtech

− Desenvolvimento de software

• Software Livre

− GNU/Linux− Python− etc.

Quem sou eu?

PythOnCampus Introdução à linguagem Python – 3 / 28

• CEFET/RJ

− Engenharia de Controle e Automação

• Chemtech

− Desenvolvimento de software

• Software Livre

− GNU/Linux− Python− etc.

Quem são vocês?

PythOnCampus Introdução à linguagem Python – 4 / 28

• Nome

• Faz o que?

• Programa em qual(is) linguagem(ns)?

• Já conhece ou ouviu falar de Python?

• Por que está aqui?

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

O que é Python?

PythOnCampus Introdução à linguagem Python – 5 / 28

• Linguagem interpretada

• Software livre

• Multiplataforma

• Procedural, OO e funcional

• VHLL: Very High Level Language

• Baterias incluídas!

− Extensa biblioteca padrão

Um pouco mais sobre Python

PythOnCampus Introdução à linguagem Python – 6 / 28

História

PythOnCampus Introdução à linguagem Python – 7 / 28

• Criada por Guido van Rossumem 1989

• Nome baseado no seriado in-glês Monty Python’s Flying

Circus

• Versão 2.0 lançada em 2000

• Versão 3.0 lançada em 2008

− Quebra de compatibilidade

História

PythOnCampus Introdução à linguagem Python – 7 / 28

• Criada por Guido van Rossumem 1989

• Nome baseado no seriado in-glês Monty Python’s Flying

Circus

• Versão 2.0 lançada em 2000

• Versão 3.0 lançada em 2008

− Quebra de compatibilidade

História

PythOnCampus Introdução à linguagem Python – 7 / 28

• Criada por Guido van Rossumem 1989

• Nome baseado no seriado in-glês Monty Python’s Flying

Circus

• Versão 2.0 lançada em 2000

• Versão 3.0 lançada em 2008

− Quebra de compatibilidade

História

PythOnCampus Introdução à linguagem Python – 7 / 28

• Criada por Guido van Rossumem 1989

• Nome baseado no seriado in-glês Monty Python’s Flying

Circus

• Versão 2.0 lançada em 2000

• Versão 3.0 lançada em 2008

− Quebra de compatibilidade

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Características

PythOnCampus Introdução à linguagem Python – 8 / 28

• Sintaxe elegante, simples e clara

• Orientada a objetos (porém procedural e funcional,também)

• Tipagem dinâmica

• Tipagem forte

• Estruturas de dados de alto nível

− tuplas, listas e dicionários

• Blocos de código são delimitados por endentação (?)

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Vantagens

PythOnCampus Introdução à linguagem Python – 9 / 28

• Fácil de aprender

• Poderosa

• Linguagem dinâmica: quase tudo acontece em runtime

• Code → Test

• Facilidade de criação de módulos

− A comunidade pode facilmente criar e compartilharfuncionalidades

• Interpretador interativo: shell

Quem usa?

PythOnCampus Introdução à linguagem Python – 10 / 28

• Empresas:

− Google, Yahoo!

− NASA, CERN

• Software:

− Trac

− GIMP, Blender, Inkscape

− BitTorrent

− Gnome

Quem usa?

PythOnCampus Introdução à linguagem Python – 10 / 28

• Empresas:

− Google, Yahoo!

− NASA, CERN

• Software:

− Trac

− GIMP, Blender, Inkscape

− BitTorrent

− Gnome

Onde roda?

PythOnCampus Introdução à linguagem Python – 11 / 28

• UNIX-likes

− GNU/Linux: padrão na grande maioria

− Ma OS X: padrão

• Windows: tem que instalar

• Nokia Series 60

• (. . . )

Onde roda?

PythOnCampus Introdução à linguagem Python – 11 / 28

• UNIX-likes

− GNU/Linux: padrão na grande maioria

− Ma OS X: padrão

• Windows: tem que instalar

• Nokia Series 60

• (. . . )

Onde roda?

PythOnCampus Introdução à linguagem Python – 11 / 28

• UNIX-likes

− GNU/Linux: padrão na grande maioria

− Ma OS X: padrão

• Windows: tem que instalar

• Nokia Series 60

• (. . . )

Onde roda?

PythOnCampus Introdução à linguagem Python – 11 / 28

• UNIX-likes

− GNU/Linux: padrão na grande maioria

− Ma OS X: padrão

• Windows: tem que instalar

• Nokia Series 60

• (. . . )

Botando a mão na massa!

PythOnCampus Introdução à linguagem Python – 12 / 28

Conceitos básicos

PythOnCampus Introdução à linguagem Python – 13 / 28

• Variáveis

• Números

− Inteiros

− De ponto flutuante

− Complexos

• Strings

− ', """ e \− Concatenação

− Slices

Conceitos básicos

PythOnCampus Introdução à linguagem Python – 13 / 28

• Variáveis

• Números

− Inteiros

− De ponto flutuante

− Complexos

• Strings

− ', """ e \− Concatenação

− Slices

Conceitos básicos

PythOnCampus Introdução à linguagem Python – 13 / 28

• Variáveis

• Números

− Inteiros

− De ponto flutuante

− Complexos

• Strings

− ', """ e \− Concatenação

− Slices

Mais conceitos básicos

PythOnCampus Introdução à linguagem Python – 14 / 28

• Listas

1 l i s t a = [ 'Alex' , 22 , 8 1 . 3 , [ 8 , 'CEFET' ] ]

− Acesso: lista[n℄, lista[n:℄, lista[:n℄,lista[n:m℄

− Mutáveis: lista[n℄ = valor− len(lista), lista.append()

Mais conceitos básicos

PythOnCampus Introdução à linguagem Python – 14 / 28

• Listas

1 l i s t a = [ 'Alex' , 22 , 8 1 . 3 , [ 8 , 'CEFET' ] ]

− Acesso: lista[n℄, lista[n:℄, lista[:n℄,lista[n:m℄

− Mutáveis: lista[n℄ = valor− len(lista), lista.append()

Mais conceitos básicos

PythOnCampus Introdução à linguagem Python – 14 / 28

• Listas

1 l i s t a = [ 'Alex' , 22 , 8 1 . 3 , [ 8 , 'CEFET' ] ]

− Acesso: lista[n℄, lista[n:℄, lista[:n℄,lista[n:m℄

− Mutáveis: lista[n℄ = valor− len(lista), lista.append()

Mais conceitos básicos

PythOnCampus Introdução à linguagem Python – 14 / 28

• Listas

1 l i s t a = [ 'Alex' , 22 , 8 1 . 3 , [ 8 , 'CEFET' ] ]

− Acesso: lista[n℄, lista[n:℄, lista[:n℄,lista[n:m℄

− Mutáveis: lista[n℄ = valor− len(lista), lista.append()

Estruturas condicionais

PythOnCampus Introdução à linguagem Python – 15 / 28

1 i f expressao1 :2 comando13 comando24 . . .

valor1 if expressao else valor2

Estruturas condicionais

PythOnCampus Introdução à linguagem Python – 15 / 28

1 i f expressao1 :2 comando13 comando24 . . .5 e l i f expressao2 :6 comando37 . . .

valor1 if expressao else valor2

Estruturas condicionais

PythOnCampus Introdução à linguagem Python – 15 / 28

1 i f expressao1 :2 comando13 comando24 . . .5 e l i f expressao2 :6 comando37 . . .8 e lse :9 comandoN

10 . . .

valor1 if expressao else valor2

Estruturas condicionais

PythOnCampus Introdução à linguagem Python – 15 / 28

1 i f expressao1 :2 comando13 comando24 . . .5 e l i f expressao2 :6 comando37 . . .8 e lse :9 comandoN

10 . . .

• valor1 if expressao else valor2

Estruturas de repetição

PythOnCampus Introdução à linguagem Python – 16 / 28

1 f o r i i n i t e r a v e l :2 comando13 comando2

list range() di t

break ontinue pass for... else

Estruturas de repetição

PythOnCampus Introdução à linguagem Python – 16 / 28

1 f o r i i n i t e r a v e l :2 comando13 comando2

• iterável → list, range(), di t, etc.

break ontinue pass for... else

Estruturas de repetição

PythOnCampus Introdução à linguagem Python – 16 / 28

1 f o r i i n i t e r a v e l :2 comando13 comando2

• iterável → list, range(), di t, etc.

1 whi le expressao :2 comando3

break ontinue pass for... else

Estruturas de repetição

PythOnCampus Introdução à linguagem Python – 16 / 28

1 f o r i i n i t e r a v e l :2 comando13 comando2

• iterável → list, range(), di t, etc.

1 whi le expressao :2 comando3

• break, ontinue, pass, for... else

Funções

PythOnCampus Introdução à linguagem Python – 17 / 28

1 def f uncao ( param1 , param2 , . . . ) :2 comando13 . . .4 [ r e t u r n v a l o r ]

• *args

• **kwargs → param1=valor, param2=valor, . . .

• lambda: funções anônimas

• docstrings

Funções

PythOnCampus Introdução à linguagem Python – 17 / 28

1 def f uncao ( param1 , param2 , . . . ) :2 comando13 . . .4 [ r e t u r n v a l o r ]

• *args

• **kwargs → param1=valor, param2=valor, . . .

• lambda: funções anônimas

• docstrings

Funções

PythOnCampus Introdução à linguagem Python – 17 / 28

1 def f uncao ( param1 , param2 , . . . ) :2 comando13 . . .4 [ r e t u r n v a l o r ]

• *args

• **kwargs → param1=valor, param2=valor, . . .

• lambda: funções anônimas

• docstrings

Funções

PythOnCampus Introdução à linguagem Python – 17 / 28

1 def f uncao ( param1 , param2 , . . . ) :2 comando13 . . .4 [ r e t u r n v a l o r ]

• *args

• **kwargs → param1=valor, param2=valor, . . .

• lambda: funções anônimas

• docstrings

Funções

PythOnCampus Introdução à linguagem Python – 17 / 28

1 def f uncao ( param1 , param2 , . . . ) :2 comando13 . . .4 [ r e t u r n v a l o r ]

• *args

• **kwargs → param1=valor, param2=valor, . . .

• lambda: funções anônimas

• docstrings

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Listas

PythOnCampus Introdução à linguagem Python – 18 / 28

• .append()

• .insert()

• .remove()

• .pop()

• . ount()

• .index()• .sort()• .reverse()

Tuplas

PythOnCampus Introdução à linguagem Python – 19 / 28

1 t u p l a = ( 2 2 , 'Alex' , 9 . 6 )

• Bem mais rápidas

• Imutáveis:

1 >>> tu p l a [ 0 ] = 232 Traceback ( most r e ce n t c a l l l a s t ) :3 F i l e "<stdin >" , l i n e 1 , i n <module>4 TypeError : 'tuple' o b j e c t does not suppo r t

i tem ass ignment

Tuplas

PythOnCampus Introdução à linguagem Python – 19 / 28

1 t u p l a = ( 2 2 , 'Alex' , 9 . 6 )

• Bem mais rápidas

• Imutáveis:

1 >>> tu p l a [ 0 ] = 232 Traceback ( most r e ce n t c a l l l a s t ) :3 F i l e "<stdin >" , l i n e 1 , i n <module>4 TypeError : 'tuple' o b j e c t does not suppo r t

i tem ass ignment

Tuplas

PythOnCampus Introdução à linguagem Python – 19 / 28

1 t u p l a = ( 2 2 , 'Alex' , 9 . 6 )

• Bem mais rápidas

• Imutáveis:

1 >>> tu p l a [ 0 ] = 232 Traceback ( most r e ce n t c a l l l a s t ) :3 F i l e "<stdin >" , l i n e 1 , i n <module>4 TypeError : 'tuple' o b j e c t does not suppo r t

i tem ass ignment

Dicionários

PythOnCampus Introdução à linguagem Python – 20 / 28

1 d i c = {'Alex' : 22 , 5 : 'anos' , ( 1 , 2 ) : 'agua' ,'posi ao' : ( 3 , 4 ) }

• di [ have℄

• have in di → True ou False• Não acessa na ordem!

1 f o r c , v i n d i c . i t e r i t e m s ( ) :2 comando13 . . .

Dicionários

PythOnCampus Introdução à linguagem Python – 20 / 28

1 d i c = {'Alex' : 22 , 5 : 'anos' , ( 1 , 2 ) : 'agua' ,'posi ao' : ( 3 , 4 ) }

• di [ have℄

• have in di → True ou False• Não acessa na ordem!

1 f o r c , v i n d i c . i t e r i t e m s ( ) :2 comando13 . . .

Dicionários

PythOnCampus Introdução à linguagem Python – 20 / 28

1 d i c = {'Alex' : 22 , 5 : 'anos' , ( 1 , 2 ) : 'agua' ,'posi ao' : ( 3 , 4 ) }

• di [ have℄

• have in di → True ou False• Não acessa na ordem!

1 f o r c , v i n d i c . i t e r i t e m s ( ) :2 comando13 . . .

Dicionários

PythOnCampus Introdução à linguagem Python – 20 / 28

1 d i c = {'Alex' : 22 , 5 : 'anos' , ( 1 , 2 ) : 'agua' ,'posi ao' : ( 3 , 4 ) }

• di [ have℄

• have in di → True ou False• Não acessa na ordem!

1 f o r c , v i n d i c . i t e r i t e m s ( ) :2 comando13 . . .

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]6 >>> reduce ( lambda x , y : x + y , l i s t a )

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]6 >>> reduce ( lambda x , y : x + y , l i s t a )7 10

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]6 >>> reduce ( lambda x , y : x + y , l i s t a )7 108 >>> z i p ( l i s t a , [ 1 , 4 , 9 ] )

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]6 >>> reduce ( lambda x , y : x + y , l i s t a )7 108 >>> z i p ( l i s t a , [ 1 , 4 , 9 ] )9 [ ( 1 , 1 ) , ( 2 , 4 ) , ( 3 , 9 ) ]

Programação Funcional

PythOnCampus Introdução à linguagem Python – 21 / 28

1 >>> l i s t a = [ 1 , 2 , 3 , 4 ]2 >>> f i l t e r ( lambda x : x % 2 == 0 , l i s t a )3 [ 2 , 4 ]4 >>> map ( lambda x : x ∗ x , l i s t a )5 [ 1 , 4 , 9 , 1 6 ]6 >>> reduce ( lambda x , y : x + y , l i s t a )7 108 >>> z i p ( l i s t a , [ 1 , 4 , 9 ] )9 [ ( 1 , 1 ) , ( 2 , 4 ) , ( 3 , 9 ) ]

• List comprehension

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Módulos

PythOnCampus Introdução à linguagem Python – 22 / 28

• arquivo.py

• import arquivo

• arquivo.X, arquivo.f()• from arquivo import X, f• from arquivo import *

1 i f __name__ == '__main__' :2 p r i n t 'Sou um programa!'

3 e lse :4 p r i n t 'Sou um modulo!'

Arquivos

PythOnCampus Introdução à linguagem Python – 23 / 28

1 >>> arq = open ( 'teste.txt' , 'w' )

'Teste de es rita\n''teste.txt''Teste de es rita\n'

Arquivos

PythOnCampus Introdução à linguagem Python – 23 / 28

1 >>> arq = open ( 'teste.txt' , 'w' )2 >>> arq . w r i t e ( 'Teste de es rita\n' )3 >>> arq . c l o s e ( )

'teste.txt''Teste de es rita\n'

Arquivos

PythOnCampus Introdução à linguagem Python – 23 / 28

1 >>> arq = open ( 'teste.txt' , 'w' )2 >>> arq . w r i t e ( 'Teste de es rita\n' )3 >>> arq . c l o s e ( )4 >>> arq = open ( 'teste.txt' )

'Teste de es rita\n'

Arquivos

PythOnCampus Introdução à linguagem Python – 23 / 28

1 >>> arq = open ( 'teste.txt' , 'w' )2 >>> arq . w r i t e ( 'Teste de es rita\n' )3 >>> arq . c l o s e ( )4 >>> arq = open ( 'teste.txt' )5 >>> arq . r e a d l i n e s ( )6 [ 'Teste de es rita\n' ]

Arquivos

PythOnCampus Introdução à linguagem Python – 23 / 28

1 >>> arq = open ( 'teste.txt' , 'w' )2 >>> arq . w r i t e ( 'Teste de es rita\n' )3 >>> arq . c l o s e ( )4 >>> arq = open ( 'teste.txt' )5 >>> arq . r e a d l i n e s ( )6 [ 'Teste de es rita\n' ]

1 f o r l i n h a i n arq :2 p r i n t l i n h a

Classes

PythOnCampus Introdução à linguagem Python – 24 / 28

1 c las s NomeDaClasse :2 " " " Essa c l a s s e nao f a z muita co i s a " " "

3

4 s e l f . a t r i b u t o = v a l o r5 def metodo ( s e l f , param1 , param2 , . . . ) :6 comando1

• __init__()• Sobrecarga de operadores

• Herança múltipla

Classes

PythOnCampus Introdução à linguagem Python – 24 / 28

1 c las s NomeDaClasse :2 " " " Essa c l a s s e nao f a z muita co i s a " " "

3

4 s e l f . a t r i b u t o = v a l o r5 def metodo ( s e l f , param1 , param2 , . . . ) :6 comando1

• __init__()• Sobrecarga de operadores

• Herança múltipla

Classes

PythOnCampus Introdução à linguagem Python – 24 / 28

1 c las s NomeDaClasse :2 " " " Essa c l a s s e nao f a z muita co i s a " " "

3

4 s e l f . a t r i b u t o = v a l o r5 def metodo ( s e l f , param1 , param2 , . . . ) :6 comando1

• __init__()• Sobrecarga de operadores

• Herança múltipla

Classes

PythOnCampus Introdução à linguagem Python – 24 / 28

1 c las s NomeDaClasse :2 " " " Essa c l a s s e nao f a z muita co i s a " " "

3

4 s e l f . a t r i b u t o = v a l o r5 def metodo ( s e l f , param1 , param2 , . . . ) :6 comando1

• __init__()• Sobrecarga de operadores

• Herança múltipla

Baterias incluídas

PythOnCampus Introdução à linguagem Python – 25 / 28

• sys, os, re, string, zlib

• so ket, urllib, httplib, imaplib• time, datetime, math, random• stru t, pi kle, Pi kle, threading• logging, de imal• (. . . )

Outras Bibliotecas

PythOnCampus Introdução à linguagem Python – 26 / 28

• NumPy

• S iPy

• MatplotLib

• PyODE

• Python-OpenGL• (. . . )

Aplicações

PythOnCampus Introdução à linguagem Python – 27 / 28

• Scripts

• Computação Gráfica

• Web

• Jogos

• Aplicações Desktop

• (. . . )

The Zen of Python

PythOnCampus Introdução à linguagem Python – 28 / 28

1 impor t t h i s

top related