Variable naming in Python

Source: Internet
Author: User

A review:



Two global variables (including functions and classes):

(1) Normal variable x:

* Can be used via module.x.

* Can be used with the From module import *.


(2) Start with "_" Variable x:

* Can be used via module.x.

* cannot be used through the From module import *.

* Can be used with the From module import x.


(3) Start with "__":

* Can be used via module.x.

* cannot be used through the From module import *.

* Can be used with the From module import x.


(4) "__all__" variable:

*from Module Import *, only the variables defined in __all__ are imported.

* If you put the _ start variable into __all__, it will be imported.


Variables in three categories:

(1) Variable of class :

* Double underscore (__) variables and functions represent private variables and methods of a class, and can only be called within a class method. Note: Do not write the double underline in the back.

* But a single underline can still be called, and a single underline is only a convention.


(2) The variable of the instance:

* Variables of the same type.


Variable naming in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.