PYTHON CHALLENGE (MIND BOGGLING) QUESTION. | SoloLearn: Learn to code for FREE!

+15

PYTHON CHALLENGE (MIND BOGGLING) QUESTION.

Question: A function can have only 1 decorator? Ans: False I don't know precisely why the right answer is False because I've seen lots of Python functions with one decorator. Someone help please.

7/10/2020 8:45:06 AM

👑Tchybooxuur!

28 Answers

New Answer

+17

👑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 👍

+10

Ambiguity in grammar.

+9

Namit Jain Please explain more... 🙏 I think the question specifically said "function" and not method.

+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

+7

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!

+7

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.

+6

https://www.sololearn.com/learn/Python/2463/ On the second slide/page, it says at the bottom “A single function can have multiple decorators.”.

+5

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... 🤔

+5

Ozair Khan 😅 I think so too.

+5

Rowsej Thanks. I think you are right... 👍🏼

+5

No worries!

+5

MiKoLa🔥3L17.6L16=>L18 Yea... I agree with you 👍🏼 ☺️😌 I've sent my part of the double storm though.

+5

👑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.

+4

We can use multiple decoraters on single function as well as we use multiple function on single decorater

+4

Mikhail 😉😊 Thanks for contributing. I did a little draft in response to your request. See here. https://code.sololearn.com/clyAxheYSTAv/?ref=app

+3

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

+3

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. 🤷‍♂️

+3

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😅

+3

Akshay Panwar I understand your point. All I'm saying is, the grammar syntax could have been put together a bit more cleverly to avoid double meanings. Eg: Python functions cannot have more than 1 decorator. I think the inclusion of "only" in the syntax was sloppy.

+3

I use multiple decorators in discord.py For example, @commands.cooldown(*args) @bot.command() async def command(ctx): #code It's allowed, just not the norm.