{"id":25534,"date":"2021-11-19T09:13:15","date_gmt":"2021-11-19T03:43:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=25534"},"modified":"2021-11-19T09:13:15","modified_gmt":"2021-11-19T03:43:15","slug":"python-callable-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-callable-function-with-examples\/","title":{"rendered":"Python callable() Function with Examples"},"content":{"rendered":"
callable() Function in Python:<\/strong><\/p>\n If the specified object is callable, the callable() function returns true; otherwise, it returns False.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n object:<\/strong> It is an object that you want to see if an object is callable or not.<\/p>\n Return Value:<\/strong><\/p>\n The callable() method yields:<\/p>\n Note:<\/strong> It is important to remember that even if callable() is True, a call to the object may fail.<\/p>\n If callable() returns False, the call to the object will almost certainly fail.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n callable() Function in Python: If the specified object is callable, the callable() function returns true; otherwise, it returns False. Syntax: callable(object) Parameters object: It is an object that you want to see if an object is callable or not. Return Value: The callable() method yields: True if the object appears to be callable. False if …<\/p>\ncallable(object)<\/pre>\n
\n
Given Number = 10<\/pre>\n
Checking if the given number is callable or Not = False<\/pre>\n
A normal variable cannot be called(not callable)<\/pre>\n
Given Number = 25<\/pre>\n
Checking if the given number is callable or Not = False<\/pre>\n
callable() Function with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_numb = 10\r\n# Pass the given number as an argument to the callable() method that returns True if\r\n# the given number is callable. Otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt = callable(gvn_numb)\r\n# Print the result after checking if the given number is callable or Not.\r\nprint(\"Checking if the given number is callable or Not = \", rslt)\r\n<\/pre>\n
Checking if the given number is callable or Not = False<\/pre>\n
For Functions<\/h5>\n
\n
# Create a function say num.\r\ndef num():\r\n # Inside the function, take a variable and initialize it with some random variable.\r\n y = 10\r\n\r\n\r\n# Inside the main function, pass the above variable function attribute to\r\n# the callable() function and print it.\r\nprint(callable(num))\r\n<\/pre>\n
True<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_numb = int(input(\"Enter some random number = \"))\r\n# Pass the given number as an argument to the callable() method that returns True if\r\n# the given number is callable. Otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt = callable(gvn_numb)\r\n# Print the result after checking if the given number is callable or Not.\r\nprint(\"Checking if the given number is callable or Not = \", rslt)\r\n<\/pre>\n
Enter some random number = 25\r\nChecking if the given number is callable or Not = False<\/pre>\n","protected":false},"excerpt":{"rendered":"