Why Auto driver that python makes can make an adjustment to an unpredictable situation. For example, if a car faces another stopped car in front of it, the auto driver can also stop accordingly. That is amazing.
Python can do
The conditional statement is useful for creating a decision structure. Decision depends on condition. This allows a program to create more than one scenario. The if statement has an instruction for one ,, and another different instruction for another condition.
If statement have component, boolean and relational expression to check condition. Beside that, this if statement also have instruction to execute if condition as request.
Boolean and Relational Expression
A Boolean value has two value, True or False. Statement that use this value is Check Statement. Check Statement is statement that evaluate whether the statement true or false. In English language, is A is same with B? in Python language, A==B. faces statement tests an expression to determine whether it is true or false.
Boolean value is named after George Boole formulate some rules for reasoning about and combining this binary value (True and False). It is suit for computer that have binary value, 0 and 1.
We can get list of boolean value in Python by type : dir(True).
>>> dir(True) ['abs', 'add', 'and', 'class', 'cmp', 'coerce', 'delattr', 'div', 'divmod', 'doc', 'float', 'floordiv', 'format', 'getattribute', 'getnewargs', 'hash', 'hex', 'index', 'init', 'int', 'invert', 'long', 'lshift', 'mod', 'mul', 'neg', 'new', 'nonzero', 'oct', 'or', 'pos', 'pow', 'radd', 'rand', 'rdiv', 'rdivmod', 'reduce', 'reduce_ ex', 'repr', 'rfloordiv', 'rlshift', 'rmod', 'rmul', 'ror', 'rpow', 'rrshift', 'rshift', 'rsub', 'rtruediv', 'rxor', 'setattr', 'sizeof', 'str', 'sub', 'subclasshook', '_ truediv_', 'trunc', 'xor', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real'] "
That is a list of several
Another alternative, we can read the documentation by type “help(True) ” or “help(False) in
>>> help(True) Help on bool object:class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object" ... l
Usually, Boolean operator
|>=||Greater than or equal to|
|<=||Less than or equal to|
|!=||Not equal to|
Boolean Value in Conditional Expression
How boolean value in
>>> If condition : statement
Condition in the syntax is boolean statement. That is something that computer can evaluate whether that is True or False. True or False in the term of meet condition. That is not about morality or epistemology.
|X||Y||X and Y|
|X||Y||X or Y|
not operator can apply to one statement or more.
if the not operator
A conditional statement has
The syntax is like below.
>>> if True: # This is always True, pass # so this is always executed, but it does nothing >>> else: pass"
Chained conditionals/ nested decision
if we need more than two
Notation of chained conditional statement is like this.
That is the conditional statement inside another conditional statement.