Python path (4) conditional statements, python path conditional statements
1. Here is an example of the Python conditional statement:
If there are multiple conditions, use elif (that is, else if). Let's take a look at the nested if block:
2. Comparison is indispensable for conditional statements. Let's take a look at the identity operator is:
The result is as follows:
Let's look at a similar example:
X is y indicates that x and y are the same object, and x = y indicates that x and y are the same.
3. in: Membership Operator
4. String comparison
"alpha" < "beta"
Returns True.
5. Comparison of Sequences
[1, 2] < [2, 1]
Returns True.
Further:
[2, [1, 4]] < [2, [1, 5]]
Returns True.
6. boolean operators and, or, not
Let's take a look at the short-circuit logic:
This means that if the statement before or is true (that is, user input), the name will return the value of the preceding statement or the name will be assigned as a string <unknown>.
Python statement del a [2: 4]
The python slicing operation starts from 0, and 0 is the first. You can regard [0] as the first.
>>> Word = 'heiipa'
>>> Word [0]
'H' # Here word [0] is the first place to display 'helpa'
>>> Word [0: 2]
>>> 'Hl '# [0: 2] indicates the first to second digits of 'helpa', that is, all characters from the first digit to the third digit are displayed, word [] so on'
Del is delete. You will understand it after careful consideration.
Python input statement
Input () supports expressions and numbers, but does not support strings. Raw_input () supports strings, such:
>>> X = input ("x = ")
X = 1 + 1
>>> Print x
2
>>> X = raw_input ("x = ")
X = 1 + 1
>>> Print x
1 + 1