Using reflection, we can write one recursive inverse function that will work with strings, lists, and any other sequence that supports slicing and concatenation. If obj is a string reference, then Python will return an object of type str. Further, if we write str (), we get a string, which is an empty string. In other words, writing str () — this is the same as spelling "". Similarly, writing list () — this is the same as writing .
[ 4,3,2,1] OLLEH
Reflective functions include type (), isinstance (), callable (), dir () and getattr ().
x is not callable y is callable
called when used in OOP
class Foo1: def __call __ (self): print ('Print Something') print (callable (Foo1))
number = [1 , 2,3] print (dir (number)) characters = ["a", "b"] print (dir (number))
class Employee: salary = 25000 company_name = "pythonengineering" employee = Employee () print ('The salary is:', getattr (employee, "salary")) print ('The salary is:', employee.salary)
The salary is: 25000 The salary is: 25000
This article courtesy of Subhajit Saha . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you'd like to share more information on the topic discussed above.