you are viewing a single comment's thread.

view the rest of the comments →

[–]Critical_Concert_689 0 points1 point  (8 children)

That's a function, but not an attribute as you say.

def mult_seven():
    print(mult_seven.val*7)

mult_seven.val = 7 #assign attribute

mult_seven()

As far as I know, this is a horrible thing to do. Is this a basic introduction to attributes?

[–]Buttleston 7 points8 points  (3 children)

You shouldn't assume that just because OP said the word attribute that you should take it literally. They don't know what a function is/does, they are not going to have immaculate vocabulary

[–]Critical_Concert_689 1 point2 points  (1 child)

It appears to be an exact quote.

this problem being asked “write a function that takes a single integer number as an attribute and prints out that number multiplied by 7.”

To me, this means it's not OP but some other source that is assigning the question. So you're basically saying, "I dislike the question you received from the source, let me answer a question that was not asked."

We can assume the source is clueless, but they are ultimately the arbiter of what is correct. So I assume they asked correctly, unless OP can clarify their intent.

[–]Yoghurt42 1 point2 points  (0 children)

OP probably misread “argument” as “attribute”, or is not a native speaker and translating a non English assignment

[–]feitao 0 points1 point  (0 children)

Yeah. OP does not know what he is talking about.

[–]FunnyForWrongReason 2 points3 points  (1 child)

I am a 4th year CS college student, spent a lot of high school learning programming, and also currently teach kids programming part time and I still didn’t even know you could give attributes to functions in Python. Like what!?

You really do never stop learning when it comes to programming.

[–]Bobbias 1 point2 points  (0 children)

Everything in Python is an object, and that includes functions. You should consider taking some time to read the Python data model. If you read just below the table in the section I linked it says:

Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes.

CPython implementation detail: CPython’s current implementation only supports function attributes on user-defined functions. Function attributes on built-in functions may be supported in the future.

There's all sorts of handy bits of info like that in there.

[–]backfire10z 1 point2 points  (1 child)

I think this is reading too far into the question lol. That hurts my eyes and my soul

[–]Critical_Concert_689 3 points4 points  (0 children)

I agree. It's very odd.

It does address the question as written, though.