Home > Article > Backend Development > Detailed introduction to Python variable naming
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?
Tuple type variables in python, such as:
schoolRoles = ("student","class monitor","teacher","schoolmaster")
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”.
List type variables in python: such as:
studentList = ["zhangsan", "lisi", "wangwu"]
This is similar to List in Java.
Recommendation: List type variables should be named in the form of “variable name + List”.
Dict type variables in python: such as:
studentDict = {"name":"zhangsan", "age":"18", "sex":"男"}
This is similar to the json data format.
Suggestion: Dict type variables should be named in the form of "variable name + Dict".
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".
For example:
studentTupleList = [("zhangsan","lisi","wangwu"),("liubei","guanyu","zhangfei")], studentDictList = [{"name":"zhangsan", "age":"18", "sex":"男"},{"name":"lisi", "age":"20", "sex":"男"}]
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".
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!