python introdução
DESCRIPTION
Introdução a linguagem de programação PythonTRANSCRIPT
![Page 1: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/1.jpg)
![Page 2: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/2.jpg)
Foi criada há 22 anos, por Guido Van Rossum
![Page 3: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/3.jpg)
Por que aprender Python?
![Page 4: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/4.jpg)
Simplicidade
![Page 5: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/5.jpg)
“Olá mundo” em Java
|
public class Helloworld {
public static void main(String[] args) {
System.out.println(“Olá mundo”);
}}
![Page 6: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/6.jpg)
print(“Olá mundo”)
Mesmo programa em Python...
|
![Page 7: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/7.jpg)
print(“Olá mundo”)X
Python parece ser mais divertida, não?
Java Python
![Page 8: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/8.jpg)
É interativa! Você pergunta, ela responde.
![Page 9: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/9.jpg)
É multiplataforma! :)
![Page 10: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/10.jpg)
Ser simples não significa ser fraca...
![Page 11: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/11.jpg)
Utilizada pelas instituições abaixo
![Page 12: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/12.jpg)
No estilo Duck typing
![Page 13: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/13.jpg)
Nada de chaves ou colchetes para limitar blocos de códigos
Utilizamos o recuo da linha...
![Page 14: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/14.jpg)
Chega de conversa e vamos a a prática! =D
![Page 15: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/15.jpg)
print(“Hello World”)
Quebrando o tabu
![Page 16: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/16.jpg)
Começando com a matemática(Operações)
Sinal Operação
+ Adição
- Subtração
* Multiplicação
/ Divisão
** Potencia
% Resto
![Page 17: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/17.jpg)
Testando...
![Page 18: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/18.jpg)
Tentem resolver a seguinte equação(2-1)*4+7-(5*100/6)
![Page 19: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/19.jpg)
Legal... Mas esse resultado ficou salvo!?
![Page 20: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/20.jpg)
Não! :(
![Page 21: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/21.jpg)
Para armazenar dados no programa, utilizamos as variáveis!
![Page 22: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/22.jpg)
Em analogia...
![Page 23: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/23.jpg)
IdentificadorConteúdo armazenado
nome = “Seu nome aqui”
![Page 24: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/24.jpg)
nome = “Seu nome aqui”
idade = Sua idade aqui
curso = “Seu curso aqui”
![Page 25: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/25.jpg)
Utilizando o type
type(nome)>>>type(idade)>>>
![Page 26: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/26.jpg)
Saída de dados
print(“Seu texto aqui”)
print(sua_variavel_aqui)
![Page 27: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/27.jpg)
Para juntar valores, utilizamos virgula.
Ex:.
print(“Olá, meu nome é: ”+nome)
print(“E tenho ”,idade,“ anos”)
![Page 28: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/28.jpg)
Lembre-se!
Usa-se ',' para mostrar valores de diferentes tipos! E o '+' para valores de um mesmo tipo!
![Page 29: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/29.jpg)
Vamos começar a interação!
![Page 30: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/30.jpg)
nome = raw_input(“Digite seu nome: ”)
Identificador
Método para ler valores do tipo String
Texto a ser exibido
![Page 31: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/31.jpg)
Para ler valores numéricos, a história é diferente...
numero = input(“Digite algum número: ”)
Identificador
Método para ler valores numéricos
Texto a ser exibido
![Page 32: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/32.jpg)
Atividade 1
Vamos calcular o valor de delta! =D
Δ = b² + 4.a.c
Fórmula:
![Page 33: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/33.jpg)
Começando a tomar decisões...
![Page 34: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/34.jpg)
Operadores lógicos
Operador Descrição Exemplo
== Igual a total == 11
!= Diferente total != 11
> Maior que total > 10
< Menor que total < 20
>= Maior ou igual total >= 11
<= Menor ou igual total <= 11
![Page 35: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/35.jpg)
if(condição):
O código da condição ficará aqui!
![Page 36: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/36.jpg)
Vamos a prática! :)
a = 5b = 10
if(a<b):print(a,“ é menor que ”,b)
else:print(b, “ é maior que ”, a)
![Page 37: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/37.jpg)
O else e os if's entrelaçados!
a = 15b = 10
if(a>b):print(a,“ é maior que ”,b)
elif(a==15):print(a, “ é igual a 15”)
else:print(b, “ é maior que ”,a)
![Page 38: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/38.jpg)
Atividade 2
Ler uma idade e verificar se o mesmo é maior de idade
![Page 39: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/39.jpg)
Introduzindo as repetições
![Page 40: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/40.jpg)
Começando com o For
for i in range(valor_inicial, valor_final-1):
Para
Valor a ser incrementado
alcance(valores)
![Page 41: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/41.jpg)
Escrevendo de 1 a 1000
for i in range(1, 1001): print(i)
![Page 42: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/42.jpg)
Utilizando o while
while(condição):Bloco de código...
![Page 43: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/43.jpg)
Escrevendo de 1 a 1000
i = 0
while(i<=1000):print(i)
i += 1
Iniciando variável de incremento
Condição
Imprimindo na tela o valor
Incrementando o valor de i
Enquanto
![Page 44: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/44.jpg)
Atividade 3
Vamos escrever os 1000 primeiros números divisíveis por 7
![Page 45: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/45.jpg)
Listas!
![Page 46: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/46.jpg)
![Page 47: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/47.jpg)
frutas = [“Maçã”, “Goiaba”, “Caju”, “Limão”]
Identificador
Conteúdo
![Page 48: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/48.jpg)
Índices
![Page 49: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/49.jpg)
frutas[1]
Identificador
Índice
![Page 50: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/50.jpg)
Podem conter diferentes tipos de dados!
![Page 51: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/51.jpg)
Frutas = [“Maçã”, 2, “Goiaba”, 4, “Caju”, 3, “Limão”, 7]
![Page 52: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/52.jpg)
Recuperamos os valores através do índice!
>>> frutas[2]
>>> 'Goiaba'
![Page 53: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/53.jpg)
E tem baterias inclusas! =D
![Page 54: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/54.jpg)
loopyn.com.br
![Page 55: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/55.jpg)
Bruno Santos
twitter.com/brunno_dev
![Page 56: Python Introdução](https://reader033.vdocuments.com.br/reader033/viewer/2022061212/54965888ac7959292e8b506d/html5/thumbnails/56.jpg)
Obrigado! =D