
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Are Python functions objects?
Python creates function objects for you when you use a def statement, or when you use a lambda expression:
We can assign attributes to the function object and retrieve them as follows
Example
def foo(): pass foo.score = 20 print(type(foo)) print(foo.score) print(type(lambda x:x))
Output
We get the following output
C:/Users/TutorialsPoint1/~.py <type 'function'> 20 <type 'function'>
Yes, python functions are full objects. They can have attributes and methods like objects. The functions can have data variables and even functions written inside of them.
- Related Questions & Answers
- How exactly do Python functions return/yield objects?
- What are Python dictionary view objects?
- Why and how are Python functions hashable?
- Functools — Higher-order functions and operations on callable objects in Python
- How to pass objects to functions in C++?
- When are python objects candidates for garbage collection?
- Why are numbers represented as objects in python?
- How to pass objects to functions in C++ Program?
- Python Pandas - Determine if two Index objects are equal
- Python Mathematical Functions
- How to access Python objects within objects in Python?
- Python Code Objects
- What are functions in JavaScript?
- What are JavaScript Nested Functions?
- What are JavaScript Math Functions?
Advertisements