![]() I sometimes explain decorators (an intermediate-level Python concept) as “functions which accept functions and return functions”.īut that’s not an entirely accurate explanation. There are many classes-which-look-like-functions among the Python built-ins and in the Python standard library. We use the same syntax for constructing objects from classes and for calling functions: this fact is the main reason the word “callable” is such an important part of our Python vocabulary. When we call a class, we get an “instance” of that class. When we call a function, we get its return value. There’s no new needed: we just call the class. In Python, the syntax for instantiating a new class instance is the same as the syntax for calling a function. Python’s zip, len, and int are all often guessed to be functions, but only one of these is really a function: What about int: when we write int('4') are we calling a class or a function?.When we call len, are we calling a class or a function?. ![]() #Python3 class method map zip#
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |