Instantly share code, notes, and snippets.

# pknowledge

Last active September 1, 2018 19:00
Boolean, Comparison Operators and Logical Operators in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners 10 - Boolean, Comparison Operators and Logical Operators in Python https://www.youtube.com/watch?v=0MBLkNlffT0 >>> True True >>> False False >>> true Traceback (most recent call last): File "", line 1, in
Created August 31, 2018 20:54
Python Tutorial for Beginners - If Else statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners - If Else statements x = -100 if x != 100 and x > 0: print("x is = ") print(x) if x > 0: print("x is positive") else: print("x is negative")
Created September 1, 2018 18:50
Python Tutorial for Beginners-if..elif..else statements + nested IF statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners-if..elif..else statements + nested IF statements #------------nested IF statements-------- x = 10 if x >= 0: print("x is positive ") if (x%2) == 0: print("x is even") else: print("x is odd")
Created September 2, 2018 16:25
Python Lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 >>> x = [3, 5, 4, 9, 7, 10] >>> x [3, 5, 4, 9, 7, 10] >>> x[0] 3 >>> x[4] 7 >>> y = ['max', 1, 15.5, [3, 2]] >>> y[0] 'max'
Created September 2, 2018 19:20
Python Tuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 >>> x = (1,5,3,4,8) >>> >>> x (1, 5, 3, 4, 8) >>> x[0] 1 >>> x[4] 8 >>> x[100] Traceback (most recent call last):
Last active September 3, 2018 13:19
Python Sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 >>> A = {1, 2, 5, 4, 7, 9, 2} >>> A {1, 2, 4, 5, 7, 9} >>> len(A) 6 >>> A.add(10) >>> A {1, 2, 4, 5, 7, 9, 10} >>> A.add(10) >>> A
Created September 3, 2018 16:39
Python Dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 >>> D = {'name': 'max', 'age': 14, 'year': 2004} >>> D {'name': 'max', 'year': 2004, 'age': 14} >>> D['name'] 'max' >>> D['age'] 14 >>> E = {'name':'Tom', 15: 15, 15.1:15.1, True: True, (2,3): 5} >>> E[(2,3)] 5
Created September 5, 2018 18:10
Python Slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners - Python slice # a[start:end] # items start through end-1 # a[start:] # items start through the rest of the array # a[:end] # items from the beginning through end-1 # a[:] # a copy of the whole array # a[start:end:step] # start through not past end, by step # +---+---+---+---+---+---+ # | P | y | t | h | o | n | # +---+---+---+---+---+---+ # 0 1 2 3 4 5
Created September 6, 2018 13:14
while Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners - while Loop #--------- Example 1 --------------- i = 0 while True: print("the value of i is : ", i) i += 1 # i = i + 1 else: print("Finished while loop") #--------- Example 2 ---------------
Created September 6, 2018 14:25
Python For Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Python Tutorial for Beginners - For Loop print("For loop with Lists") A = [0, 1, 2, 3, 4, 5] # list for x in A: print(x) print("For loop with Tuples") B = (0, 1, 2, 3, 4, 5) # tuple for x in B: print(x)