###### tags: Python # Condital Logic ## If else ``` is_old = Flase is_licenced = True if is_old: print('you are old enough to drive!') elif is_licenced: print('your can drive now!') else: print('you are not of age!') if is_old and is_licenced: print('you are old enough to drive and you have a licence!') else: print('you are not of age!') ``` ## Truthy and Falsy bool('hello') = True bool('') = Flase bool(5) = True bool(0) = False ## Ternary Operator(Conditinal Expression) condition_if_true if condition else condition_if_else ``` is_friend = False can_message = 'message allowed' if is_friend else 'not allowed to message' ``` ## Short Circuiting if True or False: (False will be ignored) print('hi') ## Logical Operator * and * or * \> * \>= * < * == * != * not ## Loop iterable - list, dictionary, tuple, set, string - continue - break - pass ### For Loop ``` for item in (1,2,3,4,5): for x in ['a', 'b', 'c']: print(item, x) user = { 'name' : 'Golem', 'age' : 50, 'can_swim': False } for k, v in user.items(): print(k, v) for item in user.values(): print(item) ``` ### While Loop ``` i = 0 while i < 50: print(i) break else: print('done with all the work') while True: response = input('say something: ') if(response == 'bye'): break ``` ## Range range(100) for i in range(0, 10): print('email list for _ in range(2): print(list(range(10))) ## Enumerate for i,char in enumerate('Hellllooo')