Python Basics---considerations

Source: Internet
Author: User

Python is a computer programming language. Computer programming language and our daily use of natural language is different, the biggest difference is that natural language in different contexts have different understanding, and the computer to perform tasks according to the programming language, you must ensure that programming language written in the program can never be ambiguous, so, any programming language has its own set of syntax, The compiler or interpreter is responsible for translating the syntax-compliant program code into the machine code that the CPU can execute, and then executing. Python is no exception.

Python's syntax is simple, indented, and the code is written like this:

# This line is commented a = 123if a >= 0:print (a) else:print (-a)

A statement that begins with a # is a comment that is visible to the person and can be anything, and the interpreter ignores the comment. Each of the other lines is a statement that, when the statement ends with a colon:, the indented statement is treated as a block of code.

Indentation has pros and cons. The advantage is that you are forced to write the formatted code, but there is no rule that indents are a few spaces or tabs. In accordance with established management, you should always stick to the indentation of 4 spaces.

Another benefit of indenting is forcing you to write less indented code, and you tend to split a very long piece of code into several functions, resulting in less code being indented.

The downside of indentation is that the "copy-paste" function fails, which is the most pit-daddy place. When you refactor the code, the pasted past code must re-check that the indentation is correct. In addition, it is difficult for the IDE to format Python code just like formatted Java code.

Finally, it is important to note that the Python program is case-sensitive, and if the case is written incorrectly, the program will give an error.


This article is from the "Wuli_blog" blog, make sure to keep this source http://wuli03960405.blog.51cto.com/1470785/1929723

Python Basics---considerations

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.