Python statements and syntax

Source: Internet
Author: User

Python statements have some basic rules and special characters:

  • # Indicates that the subsequent characters are Python comments.
  • Line feed (\ n) is a standard line separator (usually one statement line)
  • Backslash (\) to continue the previous line
  • Semicolon (;) connects two statements in one row
  • Colon (:) separates the header and body of the code block
  • Statements (code blocks) are implemented using indentions.
  • Separate unused code blocks with different indentions in Depth
  • Python files are organized as modules

Variable assignment: A value is not directly assigned to a variable. in Python, objects are passed through reference. The value assignment statement of Python does not return values. The following statements are invalid:

>>> x=1>>> y=(x=x+1

No problem with chain assignment:

>>> x=1>>> y=x=x+1>>>2, 2)

Python does not support pre-and post-auto-increment/auto-increment operations like x ++ or -- x.

Repeated values:

>>> x=y=z=1>>>1>>>1>>>1

You can assign multiple values:

>>> x,y,z=1,2,>>>1>>>2>>>

Usually enclosed in parentheses to enhance code readability:

>>> (x,y,z)=(1,2,>>>1>>>2>>>

Using the multivariate value Assignment Method in Python, You can exchange values of two variables without intermediate variables:

>>> >>> x,y=1,2>>>1>>>2>>> x,y=>>>2>>>1

 

 

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.