-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaula16.py
More file actions
43 lines (30 loc) · 944 Bytes
/
aula16.py
File metadata and controls
43 lines (30 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Tupla / Imutável
print('-' * 20)
print('{:^20}'.format('TUPLAS'))
print('-' * 20)
try:
# Assim como tudo em Python, não tem restrição de tipo.
tupla = ('Item', 'Outro', 'Mais um')
tupla2 = ('a', 'b', 'c', 'd', 5)
print('Item 1:\t\t{}'.format(tupla[1]))
print('Item -1:\t{}'.format(tupla[-2]))
print('Tupla inteira:\t{}'.format(tupla))
# Para se precisarmos do índice, também dá
for pos, item in enumerate(tupla):
print(f'no índice {pos}, temos {item}')
print(f'Concatenação de duplas: {tupla + tupla2}')
print('Contar vezes em que aparece: ', tupla.count('Outro'))
# exception se não achar.
print('Índice: ', tupla2.index('c'))
print('Tentando editar: ', end='')
tupla[2] = 'opa'
except Exception as e:
print(e)
# Listas
print('-' * 20)
print('{:^20}'.format('TUPLAS'))
print('-' * 20)
try:
lista = ['Jorge', 'Adão', 'Maria', 'Fabrício']
except Exception as e:
print(f'Exceção em listas: {e}')