Basic grammar

  1. Identifiers in Python are case-sensitive.

  2. Python can display multiple statements on the same line by separating them with semicolons;

  3. Python code blocks do not use curly braces {} to control classes, functions, and other logical judgments. The most distinctive feature of python is to use indentation to write modules.
    A group of statements with the same indentation constitutes a code block, which we call a code group.
    Compound statements like if, while, def, and class start with a keyword and end with a colon ( : ) on the first line, and one or more lines of code after that line form a code group.
    if expression :
    suite
    elif expression :
    suite
    else :
    suite

  4. Single-line comments in python begin with #.

  5. '''Use three single quotes ( ) or three double quotes ( ) for multi-line comments in python """.

  6. Python can use quotation marks ( ' ), double quotation marks ( ” ), triple quotation marks ( '' or """ ) to denote strings, and quotation marks must start and end of the same type.

  7. The default output of print is a newline. If you want to achieve no newline, you need to add a comma at the end of the variable, ,

  8. In Python,
    member variables starting with an underscore "single underscore" are called protected variables, which means that only the class object and subclass objects can access these variables;
    "double underscore" starts with private members, which means that only the class object can access them. Even subclass objects cannot access this data.
    Starting and ending with a double underscore ( foo ) represents the identifier dedicated to a special method in python, such as init () for the constructor of a class.

  9. Multi-line statements
    Python statements generally use a new line as the terminator of the statement.
    But we can use a slash ( \ ) to split a line of statements into multiple lines as follows:
    total = item_one + \
    item_two + \
    item_three

  10. Variable Types
    Variable assignment in Python does not require a type declaration.
    Python has five standard data types:
    Numbers (number)
    String (string)
    List (list)
    Tuple (tuple)
    Dictionary (dictionary)
#这是第一个python脚本
'''
这是多行注释
这是多行注释,使用单引号
'''

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325565754&siteId=291194637