Sometimes I have seen people using the expression _.
in python code.
For example,
_.objectName = 23
Can someone help me out what exactly does "_." mean? Can someone give me more examples of this type with explanation?
Sometimes I have seen people using the expression _.
in python code.
For example,
_.objectName = 23
Can someone help me out what exactly does "_." mean? Can someone give me more examples of this type with explanation?
_
is a valid variable name in python (as well as most other languages.) It's conventionally used to store throw-away values you don't care about. Using the variable, as in your example, is bad form.
In your case, it's likely that you've seen that in an interpreter, where it typically aliases the last returned value.
For example:
>>> foo = 'bar'
>>> foo
'bar'
>>> _
'bar'
>>> _.upper()
'BAR'
It is sometimes used as a throwaway, e.g. make a list of ten items unrelated to range:
['foo' for _ in range(10)]
But in this case, there would be no reason to call a method or reference an attribute on it, so I think the usage you've seen is more likely attributed to interpreter use. If you see this in scripts, that would be bad form, but I've rarely seen that.