Python coding specification and python Encoding

Source: Internet
Author: User

Python coding specification and python Encoding

I. Naming rules

1. The variable name, package name, and module name are usually in lower case and can be underlined.

2. The first letter of the class name is in upper case, and the object name is in lower case. The private variables and private methods of the class are prefixed with two underscores (_).

Example: class Student: # class Name

Student = Student ("ddd") # object

3. The function name is usually in lower case.

Example: def compareNum (num1, num2)
Ii. Code indent and colon

Code indentation refers to entering spaces and tabs before each line of code to indicate the hierarchical relationship between each line of code. Code indentation and colons are used to differentiate the layers between codes.

For example, if the code indentation is incorrect, the prompt is: IndentationError: expected an indented block.

Iii. Module Import

Import Module

Example: import sys

Iv. Code comments #

Support for Chinese annotations, usually at the top of the plus #-*-cpdomg: UTF-8 -*-

V. Statement Separation

1. Separate the statement by using a semicolon or line feed.

2. Python supports writing one statement in multiple lines

Example: SQL = "select id, name "\

"From dept "\

"Where name = 'A '"

 

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.