From 18714a2278b21fd61a95d044d83573ee57472a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Wed, 2 Nov 2022 11:50:40 -0300 Subject: [PATCH] =?UTF-8?q?(Parte=201)=20M=C3=A9todos=20=C3=BAteis=20nos?= =?UTF-8?q?=20dicion=C3=A1rios=20Python=20(dict)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula76.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/aula76.py b/aula76.py index b543861..3c4ebe4 100644 --- a/aula76.py +++ b/aula76.py @@ -9,17 +9,35 @@ # pop - Apaga um item com a chave especificada (del) # popitem - Apaga o último item adicionado # update - Atualiza um dicionário com outro -import copy - -d1 = { - 'c1': 1, - 'c2': 2, - 'l1': [0, 1, 2], +p1 = { + 'nome': 'Luiz', + 'sobrenome': 'Miranda', } -d2 = d1.copy() -d2['c1'] = 1000 -d2['l1'][1] = 999999 +# p1.update({ +# 'nome1': 'AAAA', +# 'sobrenome1': 'BBBB', +# 'idade': 123, +# }) +# p1.update(idade=123, nome='Qualquer outro') +variavel = (1,) +print(variavel) +p1.update( + ( + ('Chave', 'Valor'), + ('Chave1', 'Valor1'), + ('Chave2', 'Valor1'), + ) +) +print(p1) +# print(p1.get('nome', 'Valor padrão')) -print(d1) -print(d2) +# nome = p1.pop('nome') +# print(nome) +# print(p1) + +# ultima_chave = p1.popitem() +# print(ultima_chave) +# ultima_chave = p1.popitem() +# print(ultima_chave) +# print(p1)