Difference of parameters in Python

Asked

Viewed 111 times

3

In Python, what’s the difference between Funcao(param='value') and Funcao(value)? Or else Funcao(u'value')?

I’m starting with Python and I’ve seen codes with these three forms. I don’t know if they were functions or methods, but I took everything as a function, for the record.

  • 1

    Can you clarify if your doubt consists in the definition of a function or if it is in its call? And where did you see this p'value'? Particularly I do not know this prefix. There are u, r, f and b that I know, but p never seen. Including the p nor in the official documentation.

  • @Andersoncarloswoss It was u, but I put p because I thought it was named randomly. I will correct.

1 answer

4


Funcao(param = 'value')

is a function that has a argument default, ie if the argument is not passed in the call of Funcao, the value 'value' shall be assigned to the parameter param.

Funcao(value)

I put in the Github for future reference.

In this case the parameter calls value, he is in the place of param, in the background parameters are local variables, the only difference is that they will be initialized in the function call. In this if you do not pass an argument on the call of Funcao the variable value shall have a null value (None).

Could be using in another context and there value can be a variable called value which is being passed on to Funcao() as an argument.

Funcao(u'value') is a string in Unicode encoding, nothing to do with the parameter, but it is an argument being passed, this cannot be the function statement, it has to be the call.

Without the context in each can not be sure so I gave the options.

  • I think that the context of the question, even not clear, is in the call of the function, being differentiated between positional parameters and named parameters.

  • Could be, let’s see what he says.

  • Yeah, apparently it was in the definition of the same function.

  • The u'texto' is a representation of a string in Unicode, but I am also unaware of this notation in the function https://docs.python.org/2/tutorial/introduction.html#Unicode-strings

Browser other questions tagged

You are not signed in. Login or sign up in order to post.