Pythonでhasattr() 関数を使用し変数が関数かどうかを検出してみます。 hasattr() 関数は、括弧内に引数,パラメータとして渡されたオブジェクトが括弧内で指定した属性(attribute)を持っている場合に「True(真)」を返し、そうでない場合に「False(偽)」を返します。 ■Python Google Colaboratory(Google Colab),2022年11月25日現在、Python 3.7.15を使用している。 ■hasattr() 関数を使用し変数が関数かどうかを検出するでは、hasattr() 関数を使用し変数が関数かどうかを検出するスクリプトを書いていきます。 ■コードdef test_a(a, b): return a+b print(hasattr(test_a, '__call__')) value_1 = 123 print(hasat
![Pythonでhasattr() 関数を使用し変数が関数かどうかを検出する](https://cdn-ak-scissors.b.st-hatena.com/image/square/b0e6c97966e87a40b9ffc727d8131acbff631a61/height=288;version=1;width=512/https%3A%2F%2Flaboratory.kazuuu.net%2Fwp-content%2Fuploads%2F2021%2F07%2FL.png)