28 odpowiedzi
+ 19
👑Tchybooxuur!
PYTHON CHALLENGE (MIND BOGGLING) QUESTION.
Question:
A function can have only 1 decorator?
Ans: False
In my opinion too, the answer should be True!
Obviously, a function can have ONLY 1 decorator, it is not compulsory that a function should have more than 1 decorator, though it is possible for a function to have more than 1 decorator 😃
The grammar here is the major problem
Perhaps, better put, the question could have read....
"A function cannot have more than 1 decorator"
Then Answer: False should be the correct answer 👍
+ 14
Ambiguity in grammar.
+ 9
Namit Jain
Please explain more... 🙏
I think the question specifically said "function" and not method.
+ 9
The question is, “A function can have ONLY 1 decorator”
A function can have one, or two, or three, or more, but the question is asking if there can be ONLY one decorator.
+ 9
👑 Prometheus 🇸🇬
I've seen multiple decorators being used myself... 👍🏼
I even tried my hands on one too.
https://code.sololearn.com/clyAxheYSTAv/?ref=app
+ 8
Python
On the second slide/page, it says at the bottom “A single function can have multiple decorators.”.
+ 8
I am not sure but:
When you want to refer a function to another function and at the same time you want that function to be class method too!
+ 6
Rowsej
"A single function can have multiple decorators."
The way I understand this to be is that the function can have more than one decorators.
This does not mean the function can't have one decorator... 🤔
+ 6
Ozair Khan
😅
I think so too.
+ 6
Rowsej
Thanks. I think you are right... 👍🏼
+ 6
No worries!
+ 6
MiKoLa🔥3L17.6L16=>L18
Yea...
I agree with you 👍🏼
☺️😌
I've sent my part of the double storm though.
+ 6
👑Tchybooxuur!
Clearly ,
The statement given to us is claiming that A function can have only 1 decorator
According to this statement the functions with more than one decorator should not exist.
But as we have seen many functions with more than one decorator
So such type of functions can exist.
So the final conclusion is that the statement given to us is a wrong statement.
Thus the answer to this question is False.
I hope you understand.
+ 5
We can use multiple decoraters on single function as well as we use multiple function on single decorater
+ 5
Mikhail
😉😊
Thanks for contributing.
I did a little draft in response to your request. See here.
https://code.sololearn.com/clyAxheYSTAv/?ref=app
+ 4
Actually we use multiple decoraters now and then,for Suppose clients wants to returns the values in list and in that list values must be in upper case, but client has given the lower case
+ 4
NARENDRA (Bigil)
Ok.
But this question in particular is nebulous.
And it can be read to mean that there cannot be any instance where a function has only 1 decorator. Which is confusing because I've seen plenty functions with only 1 decorator. 🤷♂️
+ 4
Nice topic, 👑Tchybooxuur! 👍👍🔥
My dear python friends, i thought i understand decorators😅 and theoretically i knew that there may be multiple decorators on a single function! BUT, once i tried to make several decorators for a single function - i failed🤦♂️
Please, if you understand this topic well - give me a clear example (code) where 2 or more decorators are used on a single function🙏
+ 4
👑Tchybooxuur! Thank you! I’ve never seen 2 decorators in action before👍💪
+ 4
Akshay Panwar yes, you are right! But there is another side of this question.
If question is: function can have only 1 decorator.
And we decide to answer: False - this also may be treated as if we answer: No, function can not have only 1 decorator.
And at this point we are wrong as well, because function really CAN have only 1 decorator, but also CAN have more than 1, or CAN have no decorators at all🤷♂️
So Tchybuxooor pointed very clearly that this question from challenges is not correct!
p.s. hope you also understand😅