Python usage experience-variable naming, python usage experience

Source: Internet
Author: User

Python usage experience-variable naming, python usage experience

Currently, the development naming rules basically follow the camper naming method, for example, userName. I don't know the features of this specification. Next, let's start with the question. How can we get a good name in python so that you can better understand the name?

 

1. Tuple type variable name

In python, Tuple type variables, such:

schoolRoles = ("student","class monitor","teacher","schoolmaster")

 

We can understand it as an array in Java.

Suggestion: Tuple type variables should be named in the form of "variable name + s" or "variable name + Tuple.

2. Name a List Type Variable

In python, List type variables include:

studentList = ["zhangsan", "lisi", "wangwu"]

 

This is similar to List in Java.

Suggestion: List type variables should be named in the form of "variable name + List.

3. Dictionary type variable name

Dict type variables in python: for example:

StudentDict = {"name": "zhangsan", "age": "18", "sex": "male "}

 

This is similar to the json data format.

Suggestion: Dict type variables should be named in the form of "variable name + Dict.

4. Set type variable name

In python, Set variables are similar to Set in Java to a sequence of unordered and non-repeating elements.

Suggestion: Set type variables should be named in the form of "variable name + Set.

5. Apply Tuple or Dict to List or Set

For example:

StudentTupleList = [("zhangsan", "lisi", "wangwu"), ("liubei", "guanyu", "zhangfei")], studentDictList = [{"name ": "zhangsan", "age": "18", "sex": "male" },{ "name": "lisi", "age": "20 ", "sex": "male"}]

 

Set as shown in the List.

Suggestion: When Tuple or Dict is applied to a List or Set, it is named in the form of "variable name + Tuple or Dict + List or Set.

Summary: simple types end with type names, complex lists or Set types end with "type name + List or Set, in this way, we can better understand the meaning and storage information of the obtained variable names and their storage methods when using python.

The above are some of my personal experiences and suggestions. If you have any better suggestions, please give feedback in a timely manner and learn from each other.

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.