Python Usage Tips-variable naming

Source: Internet
Author: User

At present, the development of naming conventions are basically followed by the hump nomenclature, such as: UserName. I'm not going to have the specs, and we all know it. Then get to the point, how to get a good name in Python, so you can better see the name of the idea?

1. Tuple (tuple) type variable name

In Python, a tuple type variable, such as: Schoolroles = ("Student", "Class monitor", "teacher", "schoolmaster"), we can correspond to an array in Java.

Recommendation: The Tuple type variable is named as "variable name +s" or "Variable name +tuple".

2. List type variable name

In Python, the list type variable: such as: Studentlist = ["Zhangsan", "Lisi", "Wangwu"], which is similar to the list in Java.

Recommendation: The List type variable is named "Variable name +list".

3. Dictionary (Dictionary) type variable name

Dict type variables in python: studentdict = {"Name": "Zhangsan", "Age": "+", "Sex": "Male"}, which is similar to JSON data format.

Recommendation: The Dict type variable is named "Variable name +dict".

4. Set (set) type variable name

In Python, a set type variable is similar to a set in Java as a sequence of unordered, non-repeating elements.

Recommendation: The Set type variable is named in the form of variable name + Set.

To apply a tuple or dict in a 5.List or set

For example: Studenttuplelist = [("Zhangsan", "Lisi", "Wangwu"), ("Liubei", "Guanyu", "Zhangfei")],

Studentdictlist = [{"Name": "Zhangsan", "Age": "+", "Sex": "Male"},{"name": "Lisi", "Age": "A", "Sex": "Male"}]

Set the list.

Recommendation: When a tuple or dict is applied in a list or set, it is named "Variable name +tuple or Dict+list or set".

Summary: The simple type ends with the type name, and the complex list or collection type ends with type name +list or set, so that we can better understand the meaning of the variable name and the stored information and how it is stored when using Python.

The above is a number of personal suggestions, if there is any better advice please feedback, we learn from each other.

Python Usage Tips-variable naming

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.