dir, hasattr e getattr em Python

This commit is contained in:
Luiz Otávio
2022-11-04 08:07:35 -03:00
parent b7eaa4aad1
commit 9cf5f5ece4

9
aula89.py Normal file
View File

@@ -0,0 +1,9 @@
# dir, hasattr e getattr em Python
string = 'Luiz'
metodo = 'strip'
if hasattr(string, metodo):
print('Existe upper')
print(getattr(string, metodo)())
else:
print('Não existe o método', metodo)