From 9d9938c31d48f32ea0efaa81297a3382d975fe62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Tue, 1 Nov 2022 10:29:45 -0300 Subject: [PATCH] =?UTF-8?q?*args=20para=20quantidade=20de=20argumentos=20n?= =?UTF-8?q?=C3=A3o=20nomeados=20vari=C3=A1veis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula71.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 aula71.py diff --git a/aula71.py b/aula71.py new file mode 100644 index 0000000..a3ba13e --- /dev/null +++ b/aula71.py @@ -0,0 +1,31 @@ +""" +args - Argumentos não nomeados +* - *args (empacotamento e desempacotamento) +""" +# Lembre-te de desempacotamento +# x, y, *resto = 1, 2, 3, 4 +# print(x, y, resto) + + +# def soma(x, y): +# return x + y + +def soma(*args): + total = 0 + for numero in args: + total += numero + return total + + +soma_1_2_3 = soma(1, 2, 3) +# print(soma_1_2_3) + +soma_4_5_6 = soma(4, 5, 6) +# print(soma_4_5_6) + +numeros = 1, 2, 3, 4, 5, 6, 7, 78, 10 +outra_soma = soma(*numeros) +print(outra_soma) + +print(sum(numeros)) +# print(*numeros)