One, the print statement
1. Basic output
Print ' I am a boy '
2. The comma of print
Print ' This is 1 ' , Print " This is 2 "
3. Output to file >> redirect
>>> f = open ('D:\Python27\print.txt','W')>>>Print>> F,"hahaha">>>Print>> F,"2hahahaah",>>>Print>> F,"I am a boy">>>f.close () Hahaha2hahahaah I am a boy
Ii. Control Flow Statements
1. Consists of condition and execution code blocks
1.1 pieces can be divided into decisions (if-decision conditions), loops (for-loop conditions) and branches (Swich-branching conditions, replaced by if elif)
2. Format (colon and four empty Geyong not forgotten)
3. If and for function, all control flow
The essence of a control flow statement is to implement business logic. conditions, whether decisions or loops, are closely related to the bool value.
Three, Boolean value
1. Control flow is closely related to true and false values
1.1 Do not misunderstand true and false with Boolean value
2. Some of the most basic operators of Boolean values
2.1 And All is true, is true.
2.2 Or as long as one is true, it is true
2.3 is
2.4 = = Check value check to see if the left and right values are the same
2.5 not
2.6 Some other comparison symbols
#-*-coding=utf-8-*-#: Colon separates conditions and blocks of code#Indent 4 Spaces#if True: #条件#Print 4 # EXECUTE code blockx= 3#It is recommended to use this method when judging what is true or false .ifX:#if x = = bool (x) Print4#It is not recommended to use this method when judging what is true or false .ifX isTrue:#Is checks whether the same data object is referenced, X is True, x refers to an integer object, and True refers to a data object with a bool value Print5#assume true (this must be a true bool value):#execute the Next statement##suppose not to be false:#execute the Next statementif notFalse:Print 'Not False'The result is notFalse
Iv. If statement (Control flow statement)
1. If the constituent if else elif pass
1.1 If and elif replace the Swich
1.2 Pass
#assume true (this must be a true bool value):#execute a hypothetical code block#otherwise:#execute hypothetical dummy blocks of codeifTrue:Print 'True'Else:Print 'False'#assume true (this must be a true bool value):#execute a hypothetical code block#Suppose false:#execute hypothetical dummy blocks of code#Otherwise (not true, nor false):#Execute CodeifTrue:Print 'True'elif notTrue:Print 'False'Else:Pass #nothing is done .
2. Artifice three-dimensional expression
2.1 X if Else
4 If True else 3
if True: Print Else 3
[4,3][true][4,3] [False]
2.2 Utilization List
[False answer, true answer] Conditions
2.3 Three-dimensional expression play just fine
Lesson 11th: Python Statement explanation