print (callable (x)) def ktraHam (): print ("Ktra") y = kdHam print (callable (y))
When you run the program, the output output will be:
False True In this example, object x cannot be called, and object y can be called.
Example 2: The object can be called class Quantrimang: def __call __ (self): print ('Print screen image') print (callable (Quantrimang)) When you run the program, the output output will be:
True So the class object here can be called.
You can continue to perform other necessary commands.
class Quantrimang: def __call __ (self): print ('Print to screen') InstanceOfQuantrimang = Quantrimang () # Prints 'Print to screen' InstanceOfQuantrimang () Example 3: The object appears but cannot be called. class Quantrimang: def printLine (self): print ('Print to screen') print (callable (Quantrimang)) When you run the program, the output output will be:
True The object in class Quantrimang here returns a call, but when executing another command an error occurs, for example:
class Quantrimang: def printLine (self): print ('Print to screen') print (callable (Quantrimang)) InstanceOfQuantrimang = Quantrimang () # Error occurred # 'Quantrimang' cannot be called InstanceOfQuantrimang () Program reported an error:
True Traceback (most recent call last): File "", line 10, print InstanceOfQuantrimang () TypeError: 'Quantrimang' object is not callable Callable () has only a few notes like that. Remember to practice regularly with Python exercises.
See more:
Bool () function in Python Ascii () function in Python Bin () function in Python Previous article: Function bytes in Python
Next article: Function chr () in Python
Lesley Montoya Update 25 May 2019
May be interested The function set () in Python in this article, tipsmake.com will learn with you about set (), syntax, parameters and specific examples. invites you to read the track.
Help () function in Python the built-in help () function in python is used to display documents and invoke the help system of modules, functions, classes, keywords ...
Sum () function in Python the built-in function sum () in python returns the sum of all numbers in iterable.
The slice () function in Python the slice () function in python returns a slice object that helps you determine how to cut an existing string.
The chr () function in Python in python, the chr () function returns a character (a string) from an integer that represents the unicode of the returned character.
The iter () function in Python continuing with the topic of python's built-in functions, the article will introduce you to the iter () function with the syntax, usage as well as specific examples. invites you to read the track.
The pow () function in Python the pow () function built into python returns the value of x with the power of y (xy). if there is a third parameter, the function returns x to the power y, the module z.
The reversed () function in Python the reversed () function is one of the built-in functions in python, used to reverse the original string returning the iterator.
Built-in Python functions in the previous article, you learned that python has a basic function type, one is a built-in function, two are user-defined functions. today, we will learn about a list of python's built-in functions.
Exec () function in Python the exec () function used to execute python programs dynamically can be string or object code. how does exec () function syntax, what parameters do it have, and how is it used? invites you to read the track.