python 1

Add # -*- coding: utf-8 -*- at the beginning of the article   to switch the encoding

1. Notes

Single line comment:  #content 

Multi-line comments: 

within ''''''
""""""

 

 

2. Variables

  • Variable names can only be any combination of letters, numbers or underscores
  • The first character of a variable name cannot be a number
  • The following keywords cannot be declared as variable names
    ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', ' except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or' , 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
  • The definition of variables should be descriptive.

3. Constants

There is no constant light in python, and it is recognized that all uppercase variables are regarded as constants.

4. Interaction

 input( ' hint text ' ) 

If you want to input an integer, add int before input!  int(input(Please enter the account number:)) 

 type()  can view the format, int (integer) str (character) bool (boolean value)

5. if

Note the format

 

if condition:
    Execute code when conditions are met
elif condition:
    If the above conditions are not met, go for this
elif condition:
    If the above conditions are not met, go for this
elif condition:
    If the above conditions are not met, go for this    
else:
    If all the above conditions are not met, go to this section

 

6. while loop

while condition:

    loop body

#When the condition is not met, stop the loop.

When a break is encountered, the current loop is stopped directly.

Encounter continue directly to start the next cycle.

 

Guess you like

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