Home  >  Article  >  Backend Development  >  python language variable naming rules

python language variable naming rules

(*-*)浩
(*-*)浩Original
2019-07-25 13:59:0645127browse

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 method

CamelCase nomenclature

The first word starts with a lowercase letter, and the first letter of subsequent words is capitalized

For example: firstName, lastName

大CamelCase Nomenclature

The first letter of each word is capitalized

For example: FirstName, LastName, CamelCase

More Python related technical articles , please visit the

Python 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!

Statement:
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