Python's variable naming and its use

Source: Internet
Author: User

The following contents are self-taught and summed up in books.

1.

Variable names can contain only letters, numbers, and underscores. Variable names can begin with a letter or underscore, but cannot be numerically
Header, for example, you can name a variable message_1, but you cannot name it 1_message.

2.

Variable names cannot contain spaces, but you can use underscores to separate words in them. For example, the variable name greeting_message
Possible, but the variable name greeting message throws an error.

3.

Do not use Python keywords and function names as variable names, that is, do not reserve words for special purposes using Python.

4.

Variable names should be both brief and descriptive. For example, name is better than N, Student_name is better than S_n, name_length
Better than Length_of_persons_name.

5.

Use the lowercase l and the capital Letter o sparingly, as they may be mistaken for numbers 1 and 0.
Creating good variable names requires a certain amount of practice, especially when the program is complex and interesting. As you write the
More and more programs, and start reading code written by others, will become more and more adept at creating meaningful variable names.

**********************************************************************************************************

Introduction of a naming rule: Hump naming method

The camel nomenclature is when a variable name or function name is a unique identifying word that is composed of one or more words.

The first word starts with a lowercase letter, the first uppercase of the second single word , or the first letter of each single word is capitalized

Small Hump MethodThe variable is usually identified by the small hump method. The Hump method means that in addition to the first word, the first letter of the word is capitalized.Large Hump MethodCompared to the small hump method, the big hump method capitalized the first letter of the initial word. Commonly used for class names, function names, properties, namespaces.

Python's variable naming and its use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.