Python aula 2

11

Click here to load reader

description

 

Transcript of Python aula 2

Page 1: Python aula 2

Minicurso  de  Programação  

Page 2: Python aula 2

Agenda  

•  Tipos  e  Operações  •  Mais  conceitos…  •  Estruturas  de  controle  de  fluxo  •  Exercícios  

Page 3: Python aula 2

String  

•  Concatenação  de  strings  •  Acesso  a  elementos  de  string  – Slices  

•  Alterar  valor  de  um  caractere    

>>> type(“string”)

>>> “debo” + “ra”

>>> “sofia”[:]

>>> variavel[2] = 2

>>> “sofia”[-1]

Page 4: Python aula 2

Lista   >>> type([“d”, 1])

•  Concatenação  de  listas  •  Acesso  a  elementos  de  listas  •  Inserir,  remover,  alterar  elementos  de  uma  lista  >>> lista [1]

>>> lista [1] = 2

>>> lista [1:1] = 2

>>> lista [:1]

>>> lista [-1]

>>> lista [1] = []

Page 5: Python aula 2

Como  representar  matrizes    uElizando  listas?  

Page 6: Python aula 2

Boolean  

•  and,  or,  not  •  >,  >=,  <,  <=,  ==,  !=,  is,  is  not  •  True,  False  

>>> 12 == 12 and 1 => 1

>>> “la” == “la” or 12 =! 12

>>> True == False

Page 7: Python aula 2

Mais  conceitos  

>>> a, b = 0, 1 >>> while b < 10: print b a, b = b, a+b >>> print “Placar: ”, 2, “x”, 3

Atribuição  MúlEpla  

Laço  iteraEvo  

Identação  

Esse  código  calcula  a  série  de  …  

Bloco  

Comando  

Page 8: Python aula 2

Estruturas  de  fluxo  

>>> x=int(raw_input(”Digite um numero inteiro:")) >>> if x < 0: print ’Número negativo’ elif x > 0: print ’Número positivo’ else: print ’Ah, eu sou zero! :P’

Cast  

Page 9: Python aula 2

For,  while  

•  Comandos  iteraEvos  

>>>  for  x  in  [1,  2,  3]:                          print  x  

Itera  sobre  os  elementos  da  lista  

Page 10: Python aula 2

Exercícios  

•  Implementar  funções  sobre  strings  e  listas  –  len  (),  reverse  ()    

•  Implementar  funções  sobre  listas  – maior  e  menor  elemento  de  uma  lista    

Page 11: Python aula 2

Até  a  próxima…