Home  >  Article  >  Backend Development  >  About python underscore usage scenarios

About python underscore usage scenarios

坏嘻嘻
坏嘻嘻Original
2018-09-14 16:38:261171browse

Python provides multiple libraries for graphical development interfaces. This article will introduce you to the usage scenarios of python underline.

  1. ##Leading single underscore

    _var

    pep 8, Convention,


    Usage scenario: Only Internal use, such as functions and variables used only within the class Note: wildcard import: from module import * will not import objects with a single leading underscore

  2. Underscore at the end

    var_

    Usage scenario: The most appropriate name of a variable has been occupied by a keyword, and you still want to use it, you can append an underscore to solve the naming problem ConflictFor example:
    class_ ,id_

  3. double leading underscore

    __var

    python The interpreter will rewrite the attribute name to avoid naming conflicts in subclasses, and rewrite it as:

    _classname__var. Simply put, just like private variables in c, it is completely transparent to subclasses and the outside. Not referenceable
    Usage scenarios: Generally an object is very important and does not want to be directly referenced by subclasses or external sources

  4. Double leading and double trailing underscores

    __var__

    Python is reserved for special purposes,

    __init___, __call__, etc. is not recommended to use # in your own code

  5. ##Single underscore
  6. _

    Usage scenario

    : Identifies a temporary or insignificant variable, often used in unpacking expressionsFor example: age is not important

    name_age_id = ('醉陌', '20', '21315271927')
    name, _, id_ = name_age_id

Related recommendations:

MySQL Connector/Python for Python 3.3_MySQL

[python tutorial] python GUI programming (Tkinter)

The above is the detailed content of About python underscore usage scenarios. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn