Check If Variable Is Function In Python
In this tutorial I will show you how to check if a variable is function in python, to create this program we will use the callable function which returns true when given a function as a parameter so we can use this to create this program now let’s see it in code.
Python Code To Check If Variable Is Function
def test(): print("Test") if callable(test) == True: print("It is a function") else: print("Not a function")
Above is the code for checking if variable is function, we have used the callable function which returns true when given a function as a parameter.
After running this program you will see that it printed that it is a function if you gave it any other variable the callable function return it false and print not a function.
Here are some more python program tutorials for you:
- Python Program To Check If Variable A Is A Dictionary.
- Python Program To Check Even Or Odd Numbers.
- Python Program To Check Composite Numbers.
- Python Program To Check Whether A Person Is Senior Citizen Or Not.
- Python Program To Check Whether A Person Is Eligible To Vote Or Not.
I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂