Page 250 - AI Computer 10
P. 250
Logical Operators
Logical Operators are used to combine two or more conditional statements and evaluates to True or False based
on the outcome of the conditions. In Python, the three logical operators are as follows:
u And Operator: The AND operator evaluates to True if both of its operands evaluate to true, otherwise it
evaluates False.
Example:
Here, ‘and’ operator evaluates to False because the second condition false.
u Or Operator: The OR operator evaluates to true if any one condition is true.
Example:
u Not Operator: The NOT operator is used to invert a value, i.e, True into False or False into true.
Example:
Here, not(50>20) evaluates to False because the expression 50>20 evalucates to True.
Assignment Operator
Assignment operator is used to assign a value specified on the RHS to the variable on the left-hand side of
assignment operator. For example,
a=5
b=6
Here, ‘=’ operator (=) assigns the value written on the right hand side to the variable on the left side of the. Python
also offers augmented assignment operators in which an arithmetic operator is combined with the assignment
operator. For example, if a=10, then a+=10 is equal as a=a+10.
Example:
Type Conversion
Type conversion refers to the process of converting the value of one datatype to another datatype. The two
types of data type conversion supported by Python are as follows:
u Implicit Type Conversion: In Implicit type conversion, Python automatically converts one data type to
another data type. This process doesn’t need any user involvement.
116
116