Below is my learning for Day 4 of #30daysofML
The datatype for boolean in python is 'bool'
Boolean operators are used for comparison
3.0 == 3
'3'== 3
Comparison operators can be combined with the arithmetic operators
Remember to use == instead of = when making comparisons.
Booleans are most useful when combined with conditional statements like if then else statement
Python has a functions as below:
- int() function which turns things into ints,
- float() functon which turns things into floats,
- bool() function which turns things into bools.
- Calling
bool()
on an integer returnsFalse
if it’s equal to 0 andTrue
otherwise. int(True)
is 1, andint(False)
is 0.
We can use non-boolean objects in if conditions and other places where a boolean would be expected. Python will implicitly treat them as their corresponding boolean value:
Here is the order of precedence of operators in Python
Operator | Description |
---|---|
| Binding or parenthesized expression, list display, dictionary display, set display |
| Subscription, slicing, call, attribute reference |
| Await expression |
| Exponentiation 5 |
| Positive, negative, bitwise NOT |
| Multiplication, matrix multiplication, division, floor division, remainder 6 |
| Addition and subtraction |
| Shifts |
| Bitwise AND |
| Bitwise XOR |
| Bitwise OR |
Comparisons, including membership tests and identity tests | |
| Boolean NOT |
Boolean AND | |
Boolean OR | |
| Conditional expression |
Lambda expression | |
| Assignment expression |
No comments:
Post a Comment