Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
classmethod() in Python
Next article icon

callable() in Python

Last Updated : 29 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to check if an object is callable in Python. In general, a callable is something that can be called. This built-in method in Python checks and returns True if the object passed appears to be callable, but may not be, otherwise False.

Python callable()

In Python, callable() function is a built-in function that we can use to check if an object is callable in Python i.e., it can be called like a function. It generally returns True if the object can be called and False if not.

callable() in Python Syntax

Syntax: callable(object)

The callable() method takes only one argument, an object, and returns one of the two values

  • returns True, if the object appears to be callable.
  • returns False, if the object is not callable.

How callable() work in Python?

In this example, we have used callable to find out if the object is callable or not.

Python3




x = 10
 
print(callable(x))
 
def geeks(x):
    return (x)
 
y = geeks
print(callable(y))
 
 

Different Scenario for Python callable()

There may be few cases where callable() works differently and returns True but the call to object fails. But if a case returns False, the calling object will never succeed.

When Object is Callable

In this example, we are using callable() function to check if an object is callable in Python. In the first case when an object is passed in the callable() method, it returns True. It is so because let is an object to the callable function Geek (which may not be in all cases). In the second case num is absolutely not a callable object, so the result is False.

Python3




# Python program to illustrate
# callable() a test function
def Geek():
    return 5
 
# an object is created of Geek()
let = Geek
print(callable(let))
 
# a test variable
num = 5 * 5
print(callable(num))
 
 

Output

True
False


In this example, we have made a class Geek to check if the class and object is callable or not.

Python3




# Python program to illustrate callable()
class Geek:
    def __call__(self):
        print('Hello GeeksforGeeks')
 
# Suggests that the Geek class is callable
print(callable(Geek))
 
# This proves that class is callable
GeekObject = Geek()
GeekObject()
 
 

Output

True
Hello GeeksforGeeks


When Object is NOT callable

In this example, we will using callable() function to check if the object is callable or not in Python. Here the object is not callable. The callable() method returns True suggesting that the Geek class is callable, but the instance of Geek is not callable() and it returns a runtime error.

Python3




# Python program to illustrate callable()
class Geek:
  def testFunc(self):
    print('Hello GeeksforGeeks')
 
# Suggests that the Geek class is callable
print(callable(Geek))
 
GeekObject = Geek()
# The object will be created but
# returns an error on calling
GeekObject()
 
 

Output:

True
Traceback (most recent call last):
File "/home/3979dc83032f2d29befe45b6ee6001a4.py", line 10, in
GeekObject()
TypeError: 'Geek' object is not callable



Next Article
classmethod() in Python

C

Chinmoy Lenka
Improve
Article Tags :
  • Python
  • Python-Built-in-functions
Practice Tags :
  • python

Similar Reads

  • __call__ in Python
    Python has a set of built-in methods and __call__ is one of them. The __call__ method enables Python programmers to write classes where the instances behave like functions and can be called like a function. When this method is defined, calling an object (obj(arg1, arg2)) automatically triggers obj._
    4 min read
  • eval in Python
    Python eval() function parse the expression argument and evaluate it as a Python expression and runs Python expression (code) within the program. Python eval() Function SyntaxSyntax: eval(expression, globals=None, locals=None) Parameters: expression: String is parsed and evaluated as a Python expres
    6 min read
  • bool() in Python
    In Python, bool() is a built-in function that is used to convert a value to a Boolean (i.e., True or False). The Boolean data type represents truth values and is a fundamental concept in programming, often used in conditional statements, loops and logical operations. bool() function evaluates the tr
    4 min read
  • float() in Python
    Python float() function is used to return a floating-point number from a number or a string representation of a numeric value. Example: Here is a simple example of the Python float() function which takes an integer as the parameter and returns its float value. C/C++ Code # convert integer value to f
    3 min read
  • classmethod() in Python
    The classmethod() is an inbuilt function in Python, which returns a class method for a given function. This means that classmethod() is a built-in Python function that transforms a regular method into a class method. When a method is defined using the @classmethod decorator (which internally calls c
    8 min read
  • call() decorator in Python
    Python Decorators are important features of the language that allow a programmer to modify the behavior of a class. These features are added functionally to the existing code. This is a type of metaprogramming when the program is modified at compile time. The decorators can be used to inject modifie
    3 min read
  • bin() in Python
    Python bin() function returns the binary string of a given integer. bin() function is used to convert integer to binary string. In this article, we will learn more about Python bin() function. Example In this example, we are using the bin() function to convert integer to binary string. C/C++ Code x
    2 min read
  • exec() in Python
    exec() function is used for the dynamic execution of Python programs which can either be a string or object code. If it is a string, the string is parsed as a suite of Python statements which is then executed unless a syntax error occurs and if it is an object code, it is simply executed. We must be
    4 min read
  • Python lambda
    In Python, an anonymous function means that a function is without a name. As we already know that def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions. Python lambda Syntax:lambda arguments : expressionPython lambda Example:[GFGTABS] Python
    4 min read
  • Python compile() Function
    Python is a high-level, general-purpose, and very popular programming language. In this article, we will learn about the Python compile() function. Python compile() Function SyntaxPython compile() function takes source code as input and returns a code object that is ready to be executed and which ca
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences