|
47 | 47 | elif x < 50:
|
48 | 48 | print('x is less than 50')
|
49 | 49 | print('rest of the code')
|
| 50 | + |
| 51 | + |
| 52 | +print('---------------------') |
| 53 | + |
| 54 | +#if with boolean operators |
| 55 | + |
| 56 | +name = "mahmod" |
| 57 | +age = 21 |
| 58 | +if name == "mahmod" and age == 21: |
| 59 | + print("welcome mahmod") |
| 60 | + |
| 61 | +if name == "mahmod" or name == "ahmad": |
| 62 | + print("you are not mahmod") |
| 63 | + |
| 64 | + |
| 65 | +print('---------------------') |
| 66 | + |
| 67 | +#python single if example: |
| 68 | + |
| 69 | +x = 100 |
| 70 | +if x == 100: print('x = 100') |
| 71 | + |
| 72 | + |
| 73 | +print('---------------------') |
| 74 | + |
| 75 | +#python single if else example: |
| 76 | + |
| 77 | +x = 5 |
| 78 | +print('x = 5') if x == 5 else print('x != 5') |
| 79 | + |
| 80 | + |
| 81 | +print('---------------------') |
| 82 | + |
| 83 | +#python conditions example: |
| 84 | + |
| 85 | +birds = {"parakeet": 1, "parrot": 2} |
| 86 | +if "parrot" in birds: |
| 87 | + print('there is a parrot') |
| 88 | + |
| 89 | + |
| 90 | +print('---------------------') |
| 91 | + |
| 92 | +#python conditions example: |
| 93 | + |
| 94 | +birds = {"parakeet": 1, "parrot": 2} |
| 95 | +if "automobile" not in birds: |
| 96 | + print('not found') |
| 97 | + |
| 98 | + |
| 99 | +print('---------------------') |
| 100 | + |
| 101 | +#python conditions example: |
| 102 | + |
| 103 | +x = 5 |
| 104 | +y = 6 |
| 105 | +z = 3 |
| 106 | +if all([x == 5, y == 6, z == 3]): |
| 107 | + print('all are true') |
| 108 | + |
| 109 | +if any([x == 2, y == 8, z == 9]): |
| 110 | + print('not all are true') |
| 111 | + |
| 112 | + |
| 113 | +print('---------------------') |
| 114 | + |
| 115 | +#python conditions example: |
| 116 | + |
| 117 | +a = 1 |
| 118 | +b = 2 |
| 119 | +if a == 1 and b == 2: |
| 120 | + print(True) |
| 121 | + |
| 122 | +if a == 0 or b == 2: |
| 123 | + print(True) |
| 124 | + |
| 125 | +if not (a == 1 and b == 3): |
| 126 | + print(True) |
| 127 | + |
| 128 | +if a != 0 and b != 3: |
| 129 | + print(True) |
| 130 | + |
| 131 | +print('---------------------') |
| 132 | + |
| 133 | +#python conditions example: |
| 134 | + |
| 135 | +x = 1 |
| 136 | +if x in (0,2,4): |
| 137 | + print('match') |
| 138 | +else: |
| 139 | + print('not found') |
0 commit comments