Home > Article > Backend Development > python language variable naming rules
Python language variable naming rules
##Variable names can only contain letters, numbers and Underline. (Recommended learning: Python video tutorial)
Variable names can start with letters or underscores, but not numbers. For example, you can name a variable message_1, but you cannot name it 1_message.
Variable names cannot contain spaces, but underscores can be used to separate words. For example, the variable name greeting_message works, but the variable name greeting message will cause an error.
Do not use Python keywords and function names as variable names, that is, do not use words reserved by Python for special purposes, such as print.
Variable names should be short and descriptive. For example, name is better than n, student_name is better than s_n, name_length is better than length_of_persons_name.
Use the lowercase letter l and the uppercase letter O with caution, as they may be mistaken for numbers 1 and 0;
Note: Lowercase Python variable names should be used.
Camel case naming method
When the variable name consists of two or more words, you can also use camel case naming methodCamelCase nomenclature
The first word starts with a lowercase letter, and the first letter of subsequent words is capitalizedFor example: firstName, lastName大CamelCase Nomenclature
The first letter of each word is capitalizedFor example: FirstName, LastName, CamelCaseMore Python related technical articles , please visit thePython Tutorial column to learn!
The above is the detailed content of python language variable naming rules. For more information, please follow other related articles on the PHP Chinese website!