Python Syntax
Judgment statement
if An expression
if An expression :
Statement 1
else :
Statement 2
If ... elif elif ... Else .....
State1 if expression else State2 ( Implementation of the three-mesh operator )
A If a > b else b
The statement is a judgment of if, and if a>b, returns the value of A; if a<=b , the value of b is returned .
Looping statements
While expression : A statement that satisfies the execution of an expression
State1
While expression : A statement that satisfies the execution of an expression
State1
Else
State2
dead loop / Infinite loop
While True:
print "Hello"
when the value of count is less than 1, when the value of count is greater than ten when launched directly
Count = 1,5,10,15
While Count < 10:
Print Count
Count + = 1
Exit ()
Circular statement Type user keyword
Break: jump out of a loop, no longer looping statements
Continue: jump out of this cycle, continue to return to the Loop statement, the next loop ;
Pass: Skip this procedure and proceed to the next procedure;
syntax for the FOR loop in python :
for I in an iterative object:
State1 ....
Range
range () is a set of numbers tool, basic structure: Span style= "Font-family:calibri" >range (start,stop,step) , from start start, Stop end, not including stop this number, step start can be omitted, default to 0 stop step 1
For, while,else,elif,if, Application of statements such as if not
1, the server host information input
2, the input of the command
1)cmd = display command line prompt, wait for user input;
2) If the command is empty, jump out of this cycle, continue to receive user commands;
3) If the command is quit, jump out of all loops and end the program ;
4) If there is a command, print "Run%s"% (cmd)
Research points :
a). dead Loop while statement;
b). The nesting of the Loop statement and the if statement ;
c). the difference between break and continue ;
3, write 99 multiplication table :
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
........
1*9=9 ......... .......... 9*9=81
Research points :
nesting for loops
range uses
4, the user input string , Print the string after the reversal ;
1) Whether the variable name is legal judgment procedure ;
2) variable name naming rules : consists of letters, underscores, or numbers, but cannot start with numbers ;
Reference point:
s = "Hello"
Please enter a variable name :
1>. determines whether the first character is composed of a letter or an underscore ;
2>. if the first word conforms to the law, determine whether the remaining characters are composed of letters, numbers, or underscores ;
5. Enter two strings, remove all ego from the second string from the first string. For example, enter "They is students." " and " Aeiou ", the first string after deletion becomes " Thy R stdnts. "
input: Each test input contains 2 characters
Output: Output the deleted string
Example:
Input
They is students.
Aeiou
Output
Thy R stdnts.
Reference point:
1) traverse str1;
2) determines whether the str1 character is a member of the str2 ( substring );
3) If it is a member, replace the character with an empty one to achieve the purpose of the deletion ;
python--syntax