Python basic syntax

Source: Internet
Author: User

The first Python program>>> print "Hello, python!";run your code directly with the command Python xxx.py in a Linux environmentLine and indent (Note!!!) )

The biggest difference between learning Python and other languages is that Python's code block does not use curly braces {} to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.

The amount of whitespace indented is variable, but all code block statements must contain the same amount of indentation whitespace, which must be strictly enforced. As shown below:

The following code will execute the error:

Executing the above code, the following error alert will appear:

Indentationerror:unindent does not match no outer indentation levelThe error indicates that you use the Indentation method is inconsistent, there are some tab indentation, there are some space indentation, to be consistent. If it isindentationerror:unexpected IndentError, the Python compiler is telling you "Hi, man, the format of your file is wrong, it's probably the wrong tab and space. "All Python is very strict in format. Therefore, you must use the same number of indent spaces in a Python code block. It is recommended that you use each indent levelsingle TabOrTwo spacesOrFour spaces, remember that you cannot mix multiple lines of statements

A new line is generally used as the Terminator for a statement in a Python statement.

But we can use a slash (\) to divide a line of statements into multiple lines of display, as follows:

Python comments

The single-line comment in 1.python starts with #. Comments can be at the end of a statement or an expression line.

A multiline comment in 2.python uses three single quotation marks ("') or three double quotation marks (" ").

‘‘‘
This is a multi-line comment, using single quotation marks
‘‘‘

"" This is a multiline comment, using double quotation marks. """

Python basic syntax

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.