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?
1. Tuple type variable naming
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”.
2. List type variable naming
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”.
3. Dictionary type variable naming
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".
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":"男"}]
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...
