0
Doubt with python function.
I read in the book "byte of python" and also saw an error coz of putting default argument before a non-default argument in a function. Like, def say(x='hello',y): print(x*y) Is there any reason for this specic way of writing parameters with default values or is it just made like that?
7 ответов
+ 2
Nah, it's a legit question. I just wanted to know if it was something you actually were looking into or if it's just a random question.
That's how python is set up. It's got a reason, just not one thats easily explained. Nothing in code is just there for no reason.
+ 1
Ty mate!
0
You could just set y to something default too, even if it's None. You could also, put x second as a parameter instead of y.
When you tried it, it gave you an error right?
partha what? Why?
0
yes, it gave an error but what I want to ask is, is there any reason to this way of writing parameters with default values? (i.e. Only those parameters which are at the end of the parameter list can be given default argument values)
0
Nah, my bad, and I mean no disrespect but I have to ask. It just makes no sense to me why someone would ask that. So if you can tell me why, like explain what you're trying to do, it can shed light on why you'd ask.
Its like asking why different countries drive on different sides of the road. There's obviously a reason, but why should it even be a question?
0
Ah sorry if I sounded too confusing, I was simply intrigued if it had something to do with HOW functions work in python.
It's fine if there is no specific reason but I would love to know if it has.
Is my question too silly? (>0<;)