Detailed introduction to Python variable naming

高洛峰
Release: 2017-03-23 14:36:32
Original
2631 people have browsed it

The current development naming standards basically follow the camel case naming method, such as: userName. I will not characterize this specification anymore, everyone understands it. Next, let’s get to the point, how to choose a good name in python so that you can better understand your name?

1. Tuple type variable naming

Tuple type variables in python, such as:

schoolRoles = ("student","class monitor","teacher","schoolmaster")
Copy after login

We can correspondingly understand them as arrays in Java.

Recommendation: Tuple type variables should be named in the form of “variable name + s” or “variable name + Tuple”.

2. List type variable naming

List type variables in python: such as:

studentList = ["zhangsan", "lisi", "wangwu"]
Copy after login

This is similar to List in Java.

Recommendation: List type variables should be named in the form of “variable name + List”.

3. Dictionary type variable naming

Dict type variables in python: such as:

studentDict = {"name":"zhangsan", "age":"18", "sex":"男"}
Copy after login

This is similar to the json data format.

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

4. Naming of Set type variables

The Set type variable in python is similar to the Set in Java, which is an unordered sequence of non-repeating elements.

Recommendation: 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":"男"},{"name":"lisi", "age":"20", "sex":"男"}]
Copy after login

Set just like List.

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

Summary: Simple types end with the type name, and complex list or set types end with "type name + List or Set", so that we can better understand the variable names when using python The meaning contained and the information stored and how it is stored.

The above are some personal opinions and suggestions. If you have any better suggestions, please give us timely feedback so that we can learn from each other.

The above is the detailed content of Detailed introduction to Python variable naming. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!