Does underscore has any special built-in meaningin Python ?

Ben Finney ben+python at benfinney.id.au
Wed Jul 29 19:42:35 EDT 2009


dandi kain <dandi.kain at gmail.com> writes:

> What is the functionality of __ or _ , leading or trailing an object ,
> class ot function ?

There is no change in functionality. It has some slight effects on
import, but as a beginner you shouldn't need to worry about that.

> Is it just a naming convention to note special functions and objects ,
> or it really mean someting to Python ?

Both. It's a strongly-adhered-to naming convention, as an indicator to
the reader how that name should be used.

    foo      Ordinary name, part of public interface
    _foo     Ordinary name, part of internal-only interface
    __foo    Ordinary name, but will be mangled (this style used rarely)
    __foo__  Name which is used in a special way by Python

There's no change in the objects themselves; the underscores rather
indicate how those names are expected to be accessed.

-- 
 \         “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\   Brain, but Tuesday Weld isn't a complete sentence.” —_Pinky and |
_o__)                                                       The Brain_ |
Ben Finney




More information about the Python-list mailing list