Conditions and operator

2. What is the condition? What can be used as conditions? Why use conditions? 
Explicit Boolean: True, False
first category: Explicit Boolean
condition may be: the comparison operators
Age = 18 is
Print (Age> 16) after the determination condition # will be a Boolean value

condition may be: True, False
is_beautiful True =
Print (is_beautiful)


implicit Boolean: all data types, wherein 0, None, false air
implicit Boolean, all values are used as the conditions to
which 0, None, an empty (the empty string, an empty list , empty dictionary) = "represents the Boolean value is False, the rest are true

3: logical operators:
# Not, and, or
Not: that condition is the result of the immediately following negated ps: not keep up with it after that condition is an indivisible whole

and: logic and about to link the two conditions and, at the same time the two conditions is true, the final result to be true

or: logical or, or about to link the two conditions, whenever there is a two conditions is True, the final result is True,
both conditions are under the False case, the end result was to False

# Prioritization:

if the individual link and just a bunch, or just a bunch of individual links or, sequentially from left to right along the operational information to
the short-circuit operation (lazy principle): and when the connection is, as long as there is a fake operation will not continue in the future, direct the outcome, or the same, or all is connected,
as long as there is a real will not continue in the future carry out operations, direct the outcome.
If it is mixed, it is necessary to consider the priority of
not> and> or
to Not calculated, and then; connected condition enclosed (), and then the rest of the plurality of conditions or connections.

4, the operator member
in: determining whether there is a character string in a large string
     
    print("egon" in "hello egon")

Determine whether the element exists in the list
    print(111 in [111,222,33])
        Determine whether the key exists in the dictionary
    print("k1" in {"k1":111,'k2':222})
    not in: 
Print ( "Egon" not in "the Hello Egon") # recommended
print (in "hello egon" not "egon") # logic above, but semantics is not clear, is not recommended

5, the identity of the operator
is: judge is equality id
==: determining whether the value is equal to

Guess you like

Origin www.cnblogs.com/h1227/p/12426215.html