My starling Learn Python (iii): Understanding Python basic Syntax (i)

Source: Internet
Author: User

Learning a development language first of course is to be familiar with its grammar, Python syntax is relatively simple, here from the basics of the beginning to understand.

Identifier
1. The first character must be a letter in the alphabet or an underscore ' _ '.
2. The other parts of the identifier are composed of letters, numbers, and underscores.
3. Identifiers are case sensitive.

Reserved words
Reserved words are keywords and cannot be used to make any identifiers. In Python, with a keyword module, the execution keyword.kwlist can output all the reserved words of the current version, as follows:

[' False ', ' None ', ' True ', ' and ', ' As ', ' Assert ', ' Break ', ' Class ', ' Continue ', ' Def ', ' Del ', ' Elif ', ' Else ', ' Except ', ' Finally ', ' For ', ' From ', ' Global ', ' If ', ' Import ', ' In ',  ' is ' ,  ' lambda ' ,  ' nonlocal ' ,  ' not ' ,  ' or ' ,  ' Pass ' ,  ' raise ' ,  ' return ' ,  ' try '   "while" ,  ' with ' ,  ' yield ' ]       

Comments
Code comments are essential in the process of writing code, and a single line of comments in Python begins with #, such as:

Print("Hello, www.5bug.wang!" )# Follow my starling learn python   

Line and indent
Python's most distinctive feature is the use of indentation to represent blocks of code, which do not require braces ({}), and the number of spaces that are indented is mutable, but statements of the same code block must contain the same number of indentation spaces.

Multi-line statements
Python is usually a line to complete a statement, but if the statement is long, we can use a backslash (\) to implement a multi-line statement.

The practice code is as follows:

Print("Hello, www.5bug.wang!.") # Follow my starling and learn python# variable DeclarationA= 1B= 2C= 3# Multi-Line code exerciseD= A + B +  Cif D >10: print (  "D greater than ten" ) else:  print ( "D less than or equal to"  print ( "code indentation exercise Statement 1" print ( "code indent practice Statement 2"   

The output is:

Hello, www.5bug.wang!.
D is less than or equal to 10
Code Indentation Practice Statement 1
Code Indentation Practice Statement 2

————————————————— – Gorgeous Split-line ————————————————— –

...... Cond

Original address: http://www.5bug.wang/share/149.html

My starling Learn Python (iii): Understanding Python basic Syntax (i)

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.