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.