├── Assignment-1 Variable n Data Types └── Assignment1.py ├── Assignment-2 Input Function └── Assignment2.py ├── Assignment-3 Conditional Statements ├── Assignment3.py └── Python Notes by Rishabh Mishra Assignment03.pdf ├── Assignment-4 Strings └── assignment4.py ├── Assignment-5 Loops └── assignment5.py ├── Assignment-6 Data Structures ├── Python Notes by Rishabh Mishra Assignment-6 Data Structures.pdf └── assignment6.py ├── Chap-1 Introduction to Python └── Python Notes by Rishabh Mishra Chap01-Introduction.pdf ├── Chap-10 Functions ├── Python Notes by Rishabh Mishra Chap10-Functions.pdf └── functions.py ├── Chap-11 Function Arguments ├── Python Notes by Rishabh Mishra Chap-11 Function Arguments.pdf └── arguments.py ├── Chap-12 Strings Format & Operators ├── Python Notes by Rishabh Mishra Chap-12 Strings Part1.pdf └── strings.py ├── Chap-13 Strings Indexing Slicing & Methods ├── Python Notes by Rishabh Mishra Chap-13 Strings Part2.pdf └── strings2.py ├── Chap-14 Loops ├── Python Notes by Rishabh Mishra Chap-14 Loops.pdf └── loops.py ├── Chap-15 Nested Loops ├── Python Notes by Rishabh Mishra Chap-15 Nested Loops.pdf └── nested_loops.py ├── Chap-16 List ├── Python Notes by Rishabh Mishra Chap-16 List.pdf └── lists.py ├── Chap-17 Tuple ├── Python Notes by Rishabh Mishra Chap-17 Tuple.pdf └── tuples.py ├── Chap-18 Sets ├── Python Notes by Rishabh Mishra Chap-18 Set.pdf └── sets.py ├── Chap-19 Dictionary ├── Python Notes by Rishabh Mishra Chap-19 Dictionary.pdf └── dictionary.py ├── Chap-2 Python Setup └── Python Notes by Rishabh Mishra-Chap02-PythonSetup.pdf ├── Chap-20 OOPs ├── Python Notes by Rishabh Mishra Chap-20 OOPs.pdf └── oops.py ├── Chap-21 Modules ├── Python Notes by Rishabh Mishra Chap-21 Modules.pdf ├── module.py └── mymodule.py ├── Chap-22 File Handling ├── Python Notes by Rishabh Mishra Chap-22 File Handling.pdf └── file_handling.py ├── Chap-3 First Program ├── Python Notes by Rishabh Mishra-Chap03-FirstProgram.pdf ├── first.py └── firstcode.py ├── Chap-4 Variables ├── Python Notes by Rishabh Mishra-Chap04-Variables.pdf └── variables.py ├── Chap-5 Data Types ├── Python Notes by Rishabh Mishra-Chap05-DataTypes.pdf └── datatypes.py ├── Chap-6 Type Casting ├── Python Notes by Rishabh Mishra-Chap06-TypeCasting.pdf └── casting.py ├── Chap-7 Input Function ├── Python Notes by Rishabh Mishra Chap-07-Input Function.pdf └── input.py ├── Chap-8 Operators ├── Python Notes by Rishabh Mishra Chap-08-Operators.pdf └── operators.py ├── Chap-9 Conditional Statements ├── Python Notes by Rishabh Mishra Chap09-Conditional Statements.pdf └── if_else.py ├── Final Project- Password Checker └── password_checker.py ├── Project-1 Calculator └── calculator.py └── README.md /Assignment-1 Variable n Data Types/Assignment1.py: -------------------------------------------------------------------------------- 1 | # assigment-1 2 | print("Hello World") 3 | print('Hello World') 4 | print("You're a good man") 5 | print('''You're a "good" person''') 6 | 7 | # Q1: Write a Python program that prints the following text exactly as it appears: 8 | 9 | print("Python is fun.") 10 | print('''"Quotes" and 'single quotes' can be tricky.''') 11 | print("\"Quotes\" and 'single quotes' can be tricky.") 12 | 13 | print("Python is fun.\n\"Quotes\" and 'single quotes' can be tricky.") 14 | 15 | # Q2: For a business create 3 variables to store- name, age, and city. 16 | # Then print a sentence that uses these variables. 17 | name = "Rishabh" 18 | age = 26 19 | city = "Prayagraj" 20 | print("My name is", name, "from", city, "& I'm", age ) 21 | 22 | print(f"My name is {name} from {city} & I'm {age}") 23 | 24 | 25 | -------------------------------------------------------------------------------- /Assignment-2 Input Function/Assignment2.py: -------------------------------------------------------------------------------- 1 | # Assignment - 2 2 | # Write a program to input student name & marks of 3 subjects. 3 | # Print name & percentage in output. 4 | 5 | student_name = input("Enter your name: ") 6 | hindi_marks = input("Enter Hindi Marks: ") 7 | maths_marks = input("Enter Maths Marks: ") 8 | science_marks = input("Enter Science Marks: ") 9 | 10 | # calcualating percentage 11 | percentage = ((int(hindi_marks) + int(maths_marks) + int(science_marks))/300)*100 12 | 13 | # # print result 14 | print(f"The result of {student_name} is {int(percentage)}%. Well done!!") 15 | 16 | # optimized solution 17 | print("Percentage Calculator") 18 | student_name = input("Enter your name: ") 19 | hindi_marks = int(input("Enter Hindi Marks: ")) 20 | maths_marks = int(input("Enter Maths Marks: ")) 21 | science_marks = int(input("Enter Science Marks: ")) 22 | 23 | # # calcualating percentage 24 | percentage = ((hindi_marks + maths_marks + science_marks)/300)*100 25 | 26 | # # print result 27 | print(f"The result of {student_name} is {int(percentage)}%. Well done!!") 28 | 29 | 30 | # Q2: Write a program that collects multiple types of data to store in a dictionary 31 | # and print output. 32 | 33 | # initializing a dictionary 34 | user_data = {} 35 | 36 | # input from user 37 | user_data['name'] = input("Enter your name: ") 38 | user_data['age'] = int(input("Enter your age: ")) 39 | user_data['height'] = float(input("Enter your height: ")) 40 | user_data['student'] = input("Are you a student (yes/no)") 41 | 42 | # print the input from user 43 | print(user_data) -------------------------------------------------------------------------------- /Assignment-3 Conditional Statements/Assignment3.py: -------------------------------------------------------------------------------- 1 | # Assignment- 3 2 | 3 | # Q1: Leap Year: Write a simple program to 4 | # determine if a given year is a leap year 5 | # using user input. 6 | 7 | # leap year condition: 8 | # 4 divisible & 100 not divisible 9 | # 400 divisible 10 | 11 | # user input 12 | year = int(input("Enter a Year (e.g. 2024): ")) 13 | 14 | # checking leap year 15 | if (year % 4 == 0 and year % 100 != 0) or \ 16 | (year % 400 == 0): 17 | print(f"{year} is leap year") 18 | else: 19 | print(f"{year} is not leap year") 20 | 21 | # Q2: Login Authentication using conditional statement. 22 | # Assume you have a predefined username and password. 23 | # Write a program that prompts the user to enter a username and password and checks whether they match. 24 | # Provide appropriate messages for the following cases: 25 | # Both username and password are correct. 26 | # Username is correct but password is incorrect. 27 | # Username is incorrect. 28 | 29 | # predefined username and password 30 | predefined_username = 'Madhav' 31 | predefined_password = 'Pass101' 32 | 33 | # prompts the user to enter a username and password 34 | username = input("Enter your username: ") 35 | password = input("Enter your password: ") 36 | 37 | # # username and password match 38 | if username == predefined_username: 39 | if password == predefined_password: 40 | print("Welcome! Login was successful.") 41 | else: 42 | print("Incorrect Password!") 43 | else: 44 | print("Invalid Username!") 45 | 46 | 47 | # Q3: Admission Eligibility: A university has the following 48 | # eligibility criteria for admission: 49 | # Marks in Mathematics >= 65 50 | # Marks in Physics >= 55 51 | # Marks in Chemistry >= 50 52 | # Total marks in all three subjects >= 180 OR- 53 | # -Total marks in Mathematics and Physics >= 140 54 | # Write a program that takes marks in three subjects as input and prints whether the student is eligible for admission. 55 | 56 | # user input 57 | print("Enter PCM marks out of 100") 58 | physics_marks = int(input("Enter Physics marks: ")) 59 | Chemistry_marks = int(input("Enter Chemistry marks: ")) 60 | Maths_marks = int(input("Enter Maths marks: ")) 61 | 62 | # Eligibility checks 63 | if (Maths_marks >= 65 and 64 | physics_marks >= 55 and 65 | Chemistry_marks >= 50 and 66 | (Maths_marks + physics_marks + Chemistry_marks) >= 180 ) or \ 67 | (Maths_marks + physics_marks) >= 140: 68 | print("You're eligible!") 69 | else: 70 | print("You're not eligible!") -------------------------------------------------------------------------------- /Assignment-3 Conditional Statements/Python Notes by Rishabh Mishra Assignment03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Assignment-3 Conditional Statements/Python Notes by Rishabh Mishra Assignment03.pdf -------------------------------------------------------------------------------- /Assignment-4 Strings/assignment4.py: -------------------------------------------------------------------------------- 1 | # Assignment-4 on Strings 2 | 3 | #1. Limit the decimal places to 2 digits using .format method and print result, for the variable pi = 3.14159265359 4 | 5 | pi = 3.14159265359 6 | 7 | print(round(pi,2)) 8 | 9 | print("Value of pi is {}".format(pi)) 10 | 11 | # using f-function formating float numbers 12 | print("Value of pi is {:.1f}".format(pi)) 13 | 14 | print("{:.1f}".format(pi)) 15 | 16 | # f-strings 17 | print(f"{pi:.2f} using f-string") 18 | 19 | 20 | 21 | 22 | #2. Extract characters from index 2 to 8 with a step of 2: Given my_string = "Python Course", slice characters from index 2 to 8, skipping every other char. 23 | my_string = "Python Course" 24 | 25 | # string[start:stop:step] 26 | print(my_string[2:8:2]) 27 | 28 | 29 | 30 | 31 | #3. Slice to get only the middle character(s): For my_string = "Madhav", use slicing to extract the middle character(s). 32 | my_string = "Madhav" # 6 chars - even 33 | # index: 012345 34 | my_string2 = "Madhava" # 7 chars - odd 35 | # index: 0123456 36 | 37 | def mid_str(word): 38 | middle = int(len(word)/2) #3 39 | if len(word) % 2 == 0: # even char len - 2 middle char 40 | return word[middle-1 : middle+1] #2:4 41 | else: # odd char len - 1 middle char 42 | return word[middle] 43 | 44 | print(mid_str(my_string2)) 45 | 46 | 47 | 48 | 49 | #4. Remove the first 3 and last 3 characters: Given my_string = "Regression Analysis", remove the first 3 and last 3 characters. 50 | 51 | my_string = "Regression Analysis" 52 | 53 | print(my_string[3:-3]) 54 | 55 | 56 | 57 | 58 | #5. Get the substring that starts 4 characters from the end to the last character: For my_string = "Classification", slice the string starting from the 4th character from the end to the last character. 59 | 60 | my_string = "Classification" 61 | print(my_string[-4:]) 62 | 63 | 64 | 65 | 66 | #6. How to Reverse a String Using Python String Methods? 67 | word = "Python" 68 | print(word[::-1]) # step value = -1 69 | 70 | 71 | 72 | 73 | #7. Write a Python function to check if a string is a palindrome using string methods. 74 | 75 | word = "madam" 76 | word2 = "madan" 77 | 78 | def is_palindrome(s): 79 | if s == s[::-1]: 80 | print(f"{s} is a palindrome") 81 | else: 82 | print(f"{s} is not a palindrome") 83 | 84 | is_palindrome(word2) 85 | 86 | 87 | #8 and 9 are homework :) 88 | 89 | #8. Difference Between find() and index() in Python? 90 | 91 | #9. Efficient String Concatenation method: Why is using join() often more efficient than using + for string concatenation in a loop? 92 | -------------------------------------------------------------------------------- /Assignment-5 Loops/assignment5.py: -------------------------------------------------------------------------------- 1 | # Assignment-5 on Loops 2 | 3 | #1: print in the same line 4 | 5 | print("Hello", "Madhav1", sep = "*" , end = " * ") 6 | print("Madhav") 7 | 8 | # while loop to print the output in the same line 9 | i = 1 10 | while i < 4: 11 | print(f"Hello Madhav {i}", end = " ") 12 | i += 1 13 | 14 | i = 1 15 | while i < 4: 16 | print(f"Hello{i}", "Madhav", sep = "*", end = " ") 17 | i += 1 18 | 19 | 20 | #2: star pattern 21 | 22 | #2.a: Triangle Pattern 23 | # nested loop to print triangle pattern 24 | n = 5 # number of rows 25 | 26 | for i in range(1, n+1): # outer loop no. of rows (1 to 5) 27 | for j in range(1, i+1): # inner loop for columns (1 to i) 28 | print("*", end = " ") # print star without new line 29 | print() # move to the nest line after each row/iteration 30 | 31 | # shortcut method 32 | for i in range(1, n+1): 33 | print("* " * i) 34 | 35 | #2.b: inverted triangle 36 | n = 5 37 | 38 | # nested loop to print inverted triangle pattern 39 | for i in range(n, 0, -1): 40 | for j in range(1, i+1): 41 | print("*", end = " ") 42 | print() 43 | 44 | #shortcut method 45 | for i in range(n, 0, -1): 46 | print("* " * i) 47 | 48 | #2.c: pyramid pattern 49 | n = 5 # no. of rows 50 | 51 | for i in range(1, n+1): # loop for no. of rows 52 | print(' ' * (n - i), end = "") # spaces to center the stars 53 | print("*" * (2 * i - 1)) # print stars 54 | 55 | # 2n-1 56 | # 1 3 5 7 57 | 58 | # shortcut using single print function 59 | for i in range(1, n+1): # loop for no. of rows 60 | print(' ' * (n - i) + "*" * (2 * i - 1)) # print stars 61 | 62 | 63 | #3: Factorial of a number 64 | 65 | def factorial(n): 66 | result = 1 67 | while n > 0: 68 | result *= n 69 | # result = result * n # 5*1, 5*4, 20*3, 60*2 70 | n -= 1 71 | return result 72 | 73 | print(factorial(5)) 74 | # 5! = 5 * 4 * 3 * 2 * 1 75 | 76 | 77 | #4: Count vowels in a string 78 | my_string = "Python by Rishabh Mishra" 79 | vowels = "aeiou" 80 | count = 0 81 | 82 | for char in my_string: 83 | if char.lower() in vowels: 84 | count += 1 85 | print("Number of vowels are", count) 86 | 87 | 88 | #5: Longest word in a string 89 | sentence = "Python by Rishabh Mishra" 90 | words = sentence.split() 91 | longest_word = "" 92 | 93 | for word in words: 94 | if len(word) > len(longest_word): 95 | longest_word = word 96 | print("The longest word is:", longest_word) 97 | 98 | 99 | #6: do-while loop in python 100 | 101 | while True: 102 | num = int(input("Enter a number greater than 10: ")) 103 | 104 | if num > 10: 105 | print(f"Valid number entered: {num}") 106 | break # exit the loop when condition is satisfied 107 | else: 108 | print("Number is not greater than 10, try again!") 109 | 110 | 111 | #7: Fibonacci Sequence 112 | 113 | def fibonacci(n): 114 | a,b = 0,1 115 | count = 0 116 | while count < n: 117 | print(a) # 0 1 1 2 3 118 | a,b = b, a+b 119 | count += 1 # 0 1 2 3 4 120 | 121 | fibonacci(10) 122 | -------------------------------------------------------------------------------- /Assignment-6 Data Structures/Python Notes by Rishabh Mishra Assignment-6 Data Structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Assignment-6 Data Structures/Python Notes by Rishabh Mishra Assignment-6 Data Structures.pdf -------------------------------------------------------------------------------- /Assignment-6 Data Structures/assignment6.py: -------------------------------------------------------------------------------- 1 | # Assignment-6 2 | # on List, Tuple, Set & Dict 3 | # data structures / collection dtype 4 | 5 | # Q1 Find the Intersection (common elements) of Two Lists? 6 | 7 | list1 = [1,2,4,5] 8 | list2 = [4,5,6,7,8] 9 | 10 | # using for loop 11 | def intersection_loop(lst1, lst2): 12 | common_list = [] 13 | for item in lst1: 14 | if item in lst2 and item not in common_list: 15 | common_list.append(item) 16 | return common_list 17 | 18 | # print(intersection_loop(list1, list2)) 19 | 20 | # using List comprehension 21 | def intersection_comp(lst1, lst2): 22 | return [item for item in lst1 if item in lst2] 23 | 24 | # print(intersection_comp(list1, list2)) 25 | 26 | 27 | # Q2 Find the Most Frequent Element in a List? 28 | numbers = [1,2,2,3,3,3,4,7,7,7,7] 29 | 30 | def most_freq(lst): 31 | max_count = 0 32 | most_freq = None 33 | for item in lst: 34 | count = lst.count(item) 35 | if count > max_count: 36 | max_count = count 37 | most_freq = item 38 | return most_freq 39 | 40 | # print(most_freq(numbers)) 41 | 42 | 43 | # Q3 Find Cumulative Sum of a List 44 | numbers = [1, 2, 3, 4] 45 | 46 | def cumulative_sum(lst): 47 | cum_sum = [] 48 | total = 0 49 | for num in lst: 50 | total += num 51 | cum_sum.append(total) 52 | return cum_sum 53 | 54 | # print(cumulative_sum(numbers)) # Using List Comp: print([sum(numbers[:i + 1]) for i in range(len(numbers))]) 55 | 56 | 57 | # Q4 Remove Duplicates from a List 58 | fruits = ["apple", "banana", "mango", "apple", "banana"] 59 | 60 | # using loop 61 | def remove_duplicates(lst): 62 | unique = [] 63 | seen = set() 64 | for item in lst: 65 | if item not in seen: 66 | unique.append(item) 67 | seen.add(item) 68 | return unique 69 | 70 | # print(remove_duplicates(fruits)) 71 | 72 | # without seen, but not good for large dataset -list 73 | def remove_duplicates(lst): 74 | unique = [] 75 | for item in lst: 76 | if item not in unique: 77 | unique.append(item) 78 | return unique 79 | 80 | # print(remove_duplicates(fruits)) 81 | 82 | # using set constructor 83 | # print(list(set(fruits))) 84 | 85 | 86 | # Q5 Find the index of an element in a tuple 87 | my_tuple = (1, 10, 2, 3, 4) 88 | 89 | def find_index(tup, elem): 90 | return tup.index(elem) if elem in tup else -1 91 | 92 | # print(find_index(my_tuple,100)) 93 | 94 | 95 | # Q6 Find the Most Frequent Value in a dictionary 96 | data = {'a': 1, 'b': 2, 'c': 1, 'd': 3, 'e': 1} 97 | 98 | def most_freq(dct): 99 | frequency = {} 100 | for value in dct.values(): 101 | if value not in frequency: 102 | frequency[value] = 0 103 | frequency[value] += 1 # 1:1, 2:1, 1:2,3:1, 1:3 104 | max_value = max(frequency, key=frequency.get) 105 | return max_value 106 | 107 | # print(most_freq(data)) 108 | 109 | 110 | # Q7 Merge Dictionaries with Summation 111 | 112 | dict1 = {'a': 10, 'b': 20, 'c': 30} 113 | dict2 = {'b': 15, 'c': 35, 'd': 25} 114 | 115 | def merge_dict(dict1, dict2): 116 | result = dict1.copy() 117 | for key, value in dict2.items(): 118 | if key in result: 119 | result[key] += value 120 | else: 121 | result[key] = value 122 | return result 123 | 124 | # print(merge_dict(dict1, dict2)) 125 | 126 | 127 | # Q8 Flatten a Nested Dictionary 128 | 129 | data = {'a': {'b': {'c': 42}, 'd': 7}, 'e': 10} 130 | #o/p {a.b.c: 42, a.d: 7, e: 10} 131 | 132 | # a, e 133 | # {'b': {'c': 42}, 'd': 7} 134 | # b, d 135 | # {'c': 42} 136 | 137 | def flatten_dict(data, parent_key= '', sep = '.'): 138 | items = {} #initialize empty dict to store flattened items 139 | for key, value in data.items(): 140 | # combine current key with parent key 141 | new_key = f"{parent_key}{sep}{key}" if parent_key else key 142 | if isinstance(value, dict): # check if dict or not 143 | # recursive flatten the nested dict 144 | items.update(flatten_dict(value, new_key, sep)) 145 | else: 146 | # adding key-value to flatten dict 147 | items[new_key] = value 148 | return items 149 | 150 | # print(flatten_dict(data)) 151 | 152 | # data = [1,2,4] 153 | # print(isinstance(data, list)) 154 | 155 | 156 | # Q9 Sort a Dictionary by Values 157 | 158 | data = {'a': 5, 'b': 9, 'c': 2, 'd': 7} 159 | 160 | # [('a',5), ('b', 9)....] 161 | 162 | def sort_by_values(data): 163 | sorted_items = sorted(data.items(), 164 | key = lambda item: item[1], 165 | reverse=True) 166 | return {key: value for key , value in sorted_items} 167 | 168 | print(sort_by_values(data)) 169 | 170 | # print(sorted([1,2,0,2,8], reverse=True)) 171 | 172 | # print(data.items()) 173 | 174 | 175 | # Q10 Access values from a nested dictionary 176 | 177 | data = { 178 | "level1": { 179 | "level2": { 180 | "level3": { 181 | "value1": 10, 182 | "value2": [1, 2, {"deep_key": 42}], 183 | "value3": {"inner_key": "target"} 184 | }, 185 | "other_key": 99 186 | }, 187 | "list_key": [ 188 | {"list_inner_key1": 88}, 189 | {"list_inner_key2": {"deep_list_key": 77}} 190 | ] 191 | } 192 | } 193 | 194 | # Tasks to Access Elements: 195 | # Retrieve 42 196 | # Retrieve "target" 197 | # Retrieve 77 198 | 199 | 200 | # 10 Access values from a nested dictionary – Solution 201 | 202 | # Tasks to Access Elements 203 | # Retrieve 42. Path: data -> level1 -> level2 -> level3 -> value2 -> [2] -> deep_key 204 | print(data["level1"]["level2"]["level3"]["value2"][2]["deep_key"]) 205 | 206 | # Retrieve "target". Path: data -> level1 -> level2 -> level3 -> value3 -> inner_key 207 | print(data["level1"]["level2"]["level3"]["value3"]["inner_key"]) 208 | 209 | # Retrieve 77. Path: data -> level1 -> list_key -> [1] -> list_inner_key2 -> deep_list_key 210 | print(data["level1"]["list_key"][1]["list_inner_key2"]["deep_list_key"]) 211 | 212 | 213 | # All the best, keep learning n keep growing --> -------------------------------------------------------------------------------- /Chap-1 Introduction to Python/Python Notes by Rishabh Mishra Chap01-Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-1 Introduction to Python/Python Notes by Rishabh Mishra Chap01-Introduction.pdf -------------------------------------------------------------------------------- /Chap-10 Functions/Python Notes by Rishabh Mishra Chap10-Functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-10 Functions/Python Notes by Rishabh Mishra Chap10-Functions.pdf -------------------------------------------------------------------------------- /Chap-10 Functions/functions.py: -------------------------------------------------------------------------------- 1 | # functions in python 2 | 3 | #create function without parameter 4 | def greetings(): 5 | print("Welcome to the python course by Rishabh!") 6 | 7 | #call function (use function) 8 | greetings() 9 | 10 | # create a function to add 2 numbers using parameter 11 | def add2numbers(a,b): #parameter (a,b) 12 | result = a + b 13 | print("The sum is: ", result) 14 | 15 | #call above sum function 16 | add2numbers(5,3) #arguments (5,3) 17 | 18 | add2numbers(a=10, b=100) 19 | 20 | add2numbers(b=50, a=10) 21 | 22 | # create a function to add 3 numbers 23 | def add3numbers(a,b,c): #parameter (a,b,c) 24 | result = a + b + c 25 | print("The sum is: ", result) 26 | 27 | #call above sum function 28 | add3numbers(5,3, 100) #arguments (5,3,100) 29 | 30 | 31 | function with return statement 32 | def add2num(a,b): 33 | return a+b 34 | # return a-b after return statement function ends 35 | 36 | sum2num = add2num(10,1) 37 | print(sum2num) 38 | 39 | # function to convert celsius to Fahrenheit- return statement 40 | def celsius_to_fahrenheit(celsius): 41 | fahrenheit = (celsius * 9/5) + 32 42 | return fahrenheit 43 | 44 | #call function 45 | temp_f = celsius_to_fahrenheit(25) 46 | print(temp_f) 47 | print("with return: ", type(temp_f)) 48 | 49 | # function to convert celsius to Fahrenheit- without return 50 | def celsius_to_fahrenheit(celsius): 51 | fahrenheit = (celsius * 9/5) + 32 52 | print(fahrenheit) 53 | 54 | #call function 55 | temp_f2 = celsius_to_fahrenheit(50) 56 | print("without return: ", type(temp_f2)) 57 | 58 | # pass statement 59 | def kuchbhi(): 60 | pass 61 | 62 | def top_right_CTA_button_type(): # code to be updated later 63 | pass 64 | 65 | print("Hello!") -------------------------------------------------------------------------------- /Chap-11 Function Arguments/Python Notes by Rishabh Mishra Chap-11 Function Arguments.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-11 Function Arguments/Python Notes by Rishabh Mishra Chap-11 Function Arguments.pdf -------------------------------------------------------------------------------- /Chap-11 Function Arguments/arguments.py: -------------------------------------------------------------------------------- 1 | # Arguments in Functions 2 | 3 | # 1. Required Arguments (single/multiple arguments) 4 | 5 | def greetings(name): # name is parameter 6 | print("Hello ", name, "!") 7 | 8 | greetings("Madhav") # Madhav is argument 9 | greetings() # required an argument to run code 10 | 11 | def intro(course_name, instructor_name): 12 | print("Welcome to ", course_name, "course by", instructor_name) 13 | 14 | intro("Python", "Rishabh") 15 | 16 | 17 | # 2. Default Arguments 18 | 19 | def greetings(name = "World"): # "World" is a default value 20 | print("Hello ", name, "!") 21 | 22 | greetings() # runs without error using default value 23 | greetings("Rishabh") 24 | 25 | 26 | # 3. Keyword Arguments (named argument) 27 | 28 | def divide(a,b): 29 | return a/b 30 | 31 | result1 = divide(100,20) # positional argument 32 | print(result1) 33 | 34 | result2 = divide(b = 100,a = 20) 35 | print(result2) 36 | 37 | 38 | # 4. Arbitrary Argument 39 | # Arbitrary Positional Argument (*args) 40 | 41 | # Note: stores arguments as tuple 42 | 43 | def add2number(a,b): 44 | return a+b 45 | 46 | result = add2number(10,11) 47 | print(result) 48 | 49 | def add3number(a,b,c): 50 | return a+b+c 51 | 52 | result1 = add3number(10,11,1) 53 | print(result1) 54 | 55 | def add_numbers(*args): 56 | print(type(args)) 57 | return sum(args) 58 | 59 | op = add_numbers(1,2,3,4) # variable no. of arguments 60 | print(op) 61 | 62 | def greetings2(*names): 63 | for name in names: 64 | print(f"Hello, {name}!") 65 | 66 | greetings2("Madhav", 'Rishabh', 'Visakha') 67 | 68 | 69 | # Arbitrary Keyword Argument (**kwargs) 70 | 71 | # Note: stores arguments as dictionary 72 | 73 | def print_details(**kwargs): 74 | # print(type(kwargs)) # dictionary type 75 | for key, value in kwargs.items(): 76 | print(f"{key}: {value}") 77 | 78 | # print_details(name = "Madhav", age = 26, city = "Delhi") 79 | 80 | print_details(name = "Madhav", age = 26) -------------------------------------------------------------------------------- /Chap-12 Strings Format & Operators/Python Notes by Rishabh Mishra Chap-12 Strings Part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-12 Strings Format & Operators/Python Notes by Rishabh Mishra Chap-12 Strings Part1.pdf -------------------------------------------------------------------------------- /Chap-12 Strings Format & Operators/strings.py: -------------------------------------------------------------------------------- 1 | # Strings in Python - PART 1 2 | 3 | # strings- chars in single, double and triple quotes 4 | 5 | name = "Madhav" # creating a string 6 | print(name) 7 | 8 | print(type(name)) # checking data type 9 | 10 | print("It's easy") 11 | print("Hello World") 12 | 13 | print(''' "kw-double Quotes" ''') 14 | 15 | print(" \"kw-double Quotes\" ") 16 | 17 | 18 | # Formatted Strings - insert variables or experssions 19 | #1. Old style formatting - % operator 20 | 21 | name = "Madhav" 22 | age = 16 23 | print("My name is %s and I'm %d" % (name, age)) 24 | # %s, %d are placeholders for the string and int 25 | 26 | 27 | #2. str.format() method 28 | 29 | name = "Madhav" 30 | age = 16 31 | print("My name is {} and I'm {}".format(name, age)) 32 | 33 | 34 | # you can reference variables by index or keyword 35 | print("My name is {0} and I'm {1}".format(name, age)) 36 | print("My name is {1} and I'm {0}".format(name, age)) 37 | 38 | print("My name is {name} and I'm {age}".format(name="Keshav", age="21")) 39 | 40 | 41 | #3. f-strings - my fav 42 | 43 | name = "Rishabh" 44 | age = 24 45 | print(f"My name is {name} and I'm {age}") 46 | 47 | print(f"My age after 5 years will be {age + 5}") 48 | 49 | 50 | # Escape Characters - backslash with chars 51 | print(''' "kw-double Quotes" ''') 52 | 53 | print(" \"kw-double Quotes\" ") # double quotes using \ 54 | 55 | print(" \'kw-single Quotes\' ") # single quote using \ 56 | 57 | print("Hello\nWorld") # new line 58 | print("Hello\tWorld") # tab - space 59 | 60 | 61 | # String Operators in Python 62 | a = "Hello" 63 | b = "Python" 64 | 65 | print(a+b) # concatenate 66 | print(a*2) # multiple copies 67 | # [] - slice, [:] - range -- scroll below 68 | 69 | if "h" in a: 70 | print("Yess") 71 | else: 72 | print("noo") 73 | 74 | 75 | if "h" not in a: 76 | print("Yess") 77 | else: 78 | print("noo") 79 | 80 | print(r"Hello\nWorld") # Raw string: suppress the escape chars 81 | 82 | 83 | # String Indexing, Slicing and methods in PART 2 -------------------------------------------------------------------------------- /Chap-13 Strings Indexing Slicing & Methods/Python Notes by Rishabh Mishra Chap-13 Strings Part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-13 Strings Indexing Slicing & Methods/Python Notes by Rishabh Mishra Chap-13 Strings Part2.pdf -------------------------------------------------------------------------------- /Chap-13 Strings Indexing Slicing & Methods/strings2.py: -------------------------------------------------------------------------------- 1 | # Strings in Python - PART 2 -- Scroll down to String Indexing 2 | 3 | # strings- chars in single, double and triple quotes 4 | 5 | name = "Madhav" # creating a string 6 | print(name) 7 | 8 | print(type(name)) # checking data type 9 | 10 | print("It's easy") 11 | print("Hello World") 12 | 13 | print(''' "kw-double Quotes" ''') 14 | 15 | print(" \"kw-double Quotes\" ") 16 | 17 | 18 | # Formatted Strings - insert variables or experssions 19 | # 1. Old style formatting - % operator 20 | 21 | name = "Madhav" 22 | age = 16 23 | print("My name is %s and I'm %d" % (name, age)) 24 | # %s, %d are placeholders for the string and int 25 | 26 | 27 | #2. str.format() method 28 | 29 | name = "Madhav" 30 | age = 16 31 | print("My name is {} and I'm {}".format(name, age)) 32 | 33 | 34 | # you can reference variables by index or keyword 35 | print("My name is {0} and I'm {1}".format(name, age)) 36 | print("My name is {1} and I'm {0}".format(name, age)) 37 | 38 | print("My name is {name} and I'm {age}".format(name="Keshav", age="21")) 39 | 40 | 41 | #3. f-strings - my fav 42 | 43 | name = "Rishabh" 44 | age = 24 45 | print(f"My name is {name} and I'm {age}") 46 | 47 | print(f"My age after 5 years will be {age + 5}") 48 | 49 | 50 | # Escape Characters - backslash with chars 51 | print(''' "kw-double Quotes" ''') 52 | 53 | print(" \"kw-double Quotes\" ") # double quotes using \ 54 | 55 | print(" \'kw-single Quotes\' ") # single quote using \ 56 | 57 | print("Hello\nWorld") # new line 58 | print("Hello\tWorld") # tab - space 59 | 60 | # String Operators in Python 61 | a = "Hello" 62 | b = "Python" 63 | 64 | print(a+b) # concatenate 65 | print(a*2) # multiple copies 66 | # [] - slice, [:] - range -- scroll below 67 | 68 | if "h" in a: 69 | print("Yess") 70 | else: 71 | print("noo") 72 | 73 | 74 | if "h" not in a: 75 | print("Yess") 76 | else: 77 | print("noo") 78 | 79 | print(r"Hello\nWorld") # Raw string: suppress the escape chars 80 | 81 | 82 | # String Indexing 83 | 84 | my_name = "MADHAV" 85 | # index: 012345 86 | 87 | print(my_name[0]) # first character of str 88 | print(my_name[1]) # second character of str 89 | print(my_name[2]) # third character of str 90 | print(my_name[3]) # fourth character of str 91 | print(my_name[4]) # fifth character of str 92 | print(my_name[5]) # sixth character of str 93 | print(my_name[-1]) 94 | 95 | name2 = "Hello World" 96 | # index: 012345678910 97 | # -ve index:1110987654321 - 98 | print(name2[5]) # blank space is also a char 99 | print(name2[-1]) # last char from str 100 | print(name2[-3]) # 3rd last char from str 101 | 102 | 103 | 104 | # String Slicing 105 | 106 | # syntax: string[start : end : step] 107 | 108 | my_name = "MADHAV" 109 | # index: 012345 110 | 111 | print(my_name[0:3]) # default step = 1 112 | print(my_name[0:3:1]) 113 | 114 | print(my_name[0:5:1]) 115 | 116 | print(my_name[3:5:1]) 117 | 118 | print(my_name[0:5:2]) # step = 2 119 | 120 | print(my_name[0:5:3]) # step = 3 121 | 122 | print(my_name[0:5:4]) # step = 4 123 | 124 | print(my_name[0:2]) # first 2 chars 125 | print(my_name[0:3]) # first 3 chars 126 | print(my_name[2:5]) # third to fifth chars 127 | print(my_name[1:4]) # second to fourth chars 128 | print(my_name[-1:]) # last char of str 129 | print(my_name[5:]) # last char of str 130 | print(my_name[-2:]) # last 2 char of str 131 | print(my_name[-3:]) # last 3 char of str 132 | print(my_name[0::2]) # every second char 133 | print(my_name[:]) # all char 134 | print(my_name[::]) # all char 135 | print(my_name[::-1]) # reverse the string 136 | 137 | 138 | # String Methods 139 | 140 | word = "Hello, Madhav" 141 | 142 | #1. len() 143 | print(len(word)) 144 | 145 | #2. upper() 146 | print(word.upper()) 147 | 148 | #3. lower() 149 | print(word.lower()) 150 | 151 | #4. count() 152 | print(word.count('M')) 153 | 154 | #5. find() 155 | print(word.find('e')) 156 | 157 | #6. Split() 158 | print(word.split(',')) 159 | print(word.split()) 160 | 161 | #7. Replace() 162 | print(word.replace("Madhav", "Keshav")) 163 | 164 | #8. title() 165 | print(word.title()) 166 | 167 | #9. strip() 168 | word2 = " Hello World " 169 | print(len(word2)) 170 | print(word2.strip()) 171 | 172 | #10. join() 173 | zwords = ("Madhav", "is", "Great") 174 | print(" ".join(zwords)) 175 | print("-".join(zwords)) -------------------------------------------------------------------------------- /Chap-14 Loops/Python Notes by Rishabh Mishra Chap-14 Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-14 Loops/Python Notes by Rishabh Mishra Chap-14 Loops.pdf -------------------------------------------------------------------------------- /Chap-14 Loops/loops.py: -------------------------------------------------------------------------------- 1 | # Loops in Python - while & for loop 2 | 3 | # while loop 4 | 5 | count = 0 6 | 7 | while count < 5: #condition 8 | print(count) 9 | count = count + 1 10 | 11 | 12 | # print numbers from 1 to 5 using while loop 13 | count = 1 14 | while count < 6: #condition 15 | print(count) 16 | # count = count + 1 17 | count += 1 18 | 19 | 20 | count = 5 21 | while count > 0: #condition 22 | print(count) 23 | # count = count + 1 24 | count -= 1 25 | else: 26 | print("while loop ended") 27 | 28 | 29 | # while True: 30 | # print("again and again!!") 31 | # check conditions to avoid infinite loop 32 | 33 | 34 | #for loop 35 | 36 | language = 'Python' # sequence 37 | 38 | for x in language: 39 | print(x) 40 | 41 | # range function 42 | # range(stop) 43 | # range(start, stop) 44 | # range(start, stop, step) 45 | 46 | for i in range(5): # stop argument 47 | print(i) 48 | 49 | for i in range(5,10): # start, stop argument 50 | print(i) 51 | 52 | for i in range(1,10,3): # start, stop, step argument 53 | print(i) 54 | 55 | for i in range(5): 56 | print(i) 57 | else: 58 | print("for loop ended") 59 | 60 | 61 | # loop control statements 62 | # 1. pass statement 63 | 64 | for i in range(5): 65 | # mann nahi hai 66 | pass 67 | 68 | count = 5 69 | while count > 0: 70 | if count == 3: 71 | pass 72 | else: 73 | print(count) 74 | count -= 1 75 | 76 | 77 | #2. break statement 78 | 79 | for i in range(5): 80 | if i == 3: 81 | break 82 | print(i) 83 | 84 | print("---------") 85 | 86 | 87 | #3. continue statement 88 | 89 | for i in range(5): 90 | if i == 3: 91 | continue 92 | print(i) 93 | 94 | 95 | # pass statment vs continue statement 96 | count = 5 97 | while count > 0: 98 | if count == 3: 99 | pass 100 | else: 101 | print(count) 102 | count -= 1 103 | 104 | # continue statement: don't try - infinite loop 105 | count = 5 106 | while count > 0: 107 | if count == 3: 108 | # continue 109 | else: 110 | print(count) 111 | count -= 1 112 | 113 | 114 | # validate user input: controlled infinite while loop using break statement 115 | while True: 116 | user_input = input("Enter 'exit' to STOP: ") 117 | if user_input == 'exit': 118 | print("congarts! You guessed it right!") 119 | break 120 | print("sorry, you entered: ", user_input) -------------------------------------------------------------------------------- /Chap-15 Nested Loops/Python Notes by Rishabh Mishra Chap-15 Nested Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-15 Nested Loops/Python Notes by Rishabh Mishra Chap-15 Nested Loops.pdf -------------------------------------------------------------------------------- /Chap-15 Nested Loops/nested_loops.py: -------------------------------------------------------------------------------- 1 | # Loops in Python - Nested Loop 2 | 3 | # loop inside another loop is Nested Loop 4 | # syntax 5 | 6 | # outer_loop: 7 | # inner_loop: 8 | # #block of code for inner loop 9 | # block of code for outer loop 10 | 11 | # print numbers from 1 to 3 for 3 times 12 | 13 | for i in range(3): 14 | # print("Outer loop iteration no, ", i) 15 | for num in range(1,4): 16 | print(num) 17 | print("- - -") 18 | 19 | # print numbers from 1 to 3 for 3 times using while-for loop : nested loop 20 | i = 1 21 | 22 | while i < 4: 23 | print("while loop iteration no.", i) 24 | for j in range(1,4): 25 | print(j) 26 | # print("- - -") 27 | i += 1 28 | 29 | 30 | # print prime numbers between range of 2 to 10 using nested loop: 31 | 32 | for num in range(2,10): 33 | for i in range(2,num): 34 | if num % i == 0: 35 | break 36 | else: 37 | print(num) -------------------------------------------------------------------------------- /Chap-16 List/Python Notes by Rishabh Mishra Chap-16 List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-16 List/Python Notes by Rishabh Mishra Chap-16 List.pdf -------------------------------------------------------------------------------- /Chap-16 List/lists.py: -------------------------------------------------------------------------------- 1 | # Lists in Python 2 | 3 | # create list 4 | 5 | my_list = [1,2,3] 6 | print(my_list) 7 | 8 | print(type(my_list)) 9 | 10 | my_list2 = [1, 'Madhav', 'Keshav', True, 3.14] 11 | print(my_list2) 12 | print(type(my_list2)) 13 | 14 | my_list3 = [1,2, [3,4] ,True, [5,6,7] ] 15 | print(my_list3) 16 | print(type(my_list3)) 17 | 18 | 19 | # Access list - Indexing 20 | list1 = [10, 20, 30, 40, 50] 21 | # index: 0 1 2 3 4 22 | # index:-5 -4 -3 -2 -1 23 | 24 | # first element 25 | print(list1[0]) 26 | 27 | # second element 28 | print(list1[1]) 29 | 30 | # last element 31 | print(list1[-1]) 32 | 33 | # second last element 34 | print(list1[-2]) 35 | 36 | 37 | # list - slicing 38 | 39 | list2 = [10, 20, 30, 40, 50, 60, 100] 40 | # index: 0 1 2 3 4 5 6 41 | # index: -7 -6 -5 -4 -3 -2 -1 42 | 43 | # slicing syntax 44 | # list_name[start : stop : step] 45 | 46 | # start is inclusive, default is 0 47 | # stop is exclusive, default is -1/last index value 48 | 49 | # first 3 elements 50 | print(list2[0:3:1]) 51 | 52 | # elements from index 1 to 4 53 | print(list2[1:5]) 54 | 55 | # last 3 elements 56 | print(list2[-3:]) 57 | 58 | # alternative elements 59 | print(list2[::2]) #step is 2 60 | 61 | # reverse list 62 | print(list2[::-1]) #step is -1 63 | 64 | 65 | # list modify 66 | 67 | my_list = ['apple', 'banana', 'cherry'] 68 | 69 | print(my_list) 70 | 71 | # replace element at index 1 72 | my_list[1] = "blueberry" 73 | print(my_list) 74 | 75 | # add element in list 76 | my_list.append("Mango") 77 | print(my_list) 78 | 79 | # remove element from the list 80 | my_list.remove("cherry") 81 | print(my_list) 82 | 83 | 84 | # list methods 85 | 86 | # 1 append 87 | fruits = ["apple", "banana", "orange"] 88 | fruits.append("cherry") 89 | # fruits.append(108) 90 | print(fruits) 91 | 92 | 93 | #2 extend 94 | fruits = ["apple", "orange"] 95 | more_fruits = ["cherry", "mango"] # anaother list 96 | fruits.extend(more_fruits) 97 | print(fruits) 98 | 99 | 100 | #3 insert 101 | fruits = ["apple", "orange"] 102 | fruits.insert(1, "blueberry") 103 | print(fruits) 104 | 105 | 106 | #4 remove 107 | fruits = ["apple", "banana", "orange", "banana"] 108 | fruits.remove("banana") 109 | print(fruits) 110 | 111 | 112 | #5 clear 113 | fruits = ["apple", "orange"] 114 | fruits.clear() # empty list 115 | print(fruits) 116 | 117 | 118 | #6 finding index 119 | fruits = ["apple", "banana", "cherry", "banana"] 120 | index = fruits.index("banana") 121 | print(index) # Output: 1 122 | 123 | # finding index - within a range 124 | index = fruits.index("banana", 2) 125 | print(index) # Output: 3 126 | 127 | 128 | #7 count elements 129 | fruits = ["apple", "banana", "cherry", "banana"] 130 | count = fruits.count("banana") 131 | print(count) # Output: 2 132 | 133 | 134 | #8 Reverse list 135 | fruits = ["apple", "banana", "cherry"] 136 | fruits.reverse() 137 | print(fruits) 138 | 139 | 140 | # 9 sorting list 141 | numbers = [40, 10, 30, 20] 142 | numbers.sort() # default sort asc order 143 | print(numbers) 144 | 145 | # sorting list in descending order 146 | numbers.sort(reverse=True) 147 | print(numbers) 148 | 149 | # Sorting strings in a list 150 | fruits = ["cherry", "apple", "banana", 'blueberry'] 151 | fruits.sort() # default by chars asc order 152 | print(fruits) 153 | 154 | # Sorting with a key 155 | fruits.sort(key=len, reverse=True) # sort based on len 156 | print(fruits) 157 | 158 | 159 | # 10 pop with index value 160 | numbers = [10, 20, 30, 40] 161 | popped = numbers.pop(2) 162 | print(popped) # Output: pop 2nd index value 30 163 | print(numbers) 164 | 165 | # pop with defualt 166 | last = numbers.pop() 167 | print(last) # Output: pop last value by default 40 168 | print(numbers) 169 | 170 | 171 | #11 copying list 172 | fruits = ["apple", "banana", "cherry"] 173 | copy_fruits = fruits.copy() # shallow copy 174 | print(copy_fruits) 175 | 176 | # copying list - Modifying the copy does not affect the original list 177 | copy_fruits.append("mango") 178 | print(copy_fruits) 179 | print(fruits) 180 | 181 | 182 | # Join Lists 183 | 184 | list1 = [1,2,3] 185 | list2 = ['a', 'b'] 186 | 187 | # using + operator 188 | final_list = list1 + list2 189 | print(final_list) 190 | 191 | # using append method 192 | for x in list2: 193 | list1.append(x) 194 | print(list1) 195 | 196 | # using extend method 197 | list1.extend(list2) 198 | print(list1) 199 | 200 | 201 | # List comprehensions 202 | 203 | # syntax: 204 | # list_name = [expressions for item in iterable if condition] 205 | 206 | # 3 main components of list comprehension 207 | # expression, for clasue, if condition 208 | 209 | # Create a list of squares 210 | squares = [x**2 for x in range(1,6)] 211 | print(squares) 212 | 213 | # filter even numbers 214 | even_list = [x for x in range(1,20) if x%2 == 0] 215 | print(even_list) 216 | 217 | # apply function to each element of a list 218 | my_list = ['apple', 'mango', 'cherry'] 219 | 220 | my_name = "madhav" 221 | print(my_name) 222 | print(my_name.upper()) 223 | 224 | print(my_list) 225 | # print(my_list.upper()) # wrong way 226 | 227 | uppercase_list = [lst.upper() for lst in my_list] 228 | print(uppercase_list) 229 | 230 | # flatten a nested list using list comp 231 | nested_list = [[1,2], [3,4], [5,6]] 232 | 233 | result = [item for sublist in nested_list for item in sublist] 234 | print(result) 235 | 236 | # first, [1,2] -> 1,2 237 | # second, [3,4] -> 3,4 238 | # third, [5,6] -> 5,6 239 | 240 | def flatten_list(lst): 241 | return [item for sublist in lst for item in sublist] 242 | 243 | final_list = flatten_list(nested_list) 244 | print(final_list) 245 | 246 | 247 | # List iterations 248 | 249 | fruits = ['apple', 'mango', 'cherry'] 250 | 251 | # using for loop 252 | for fruit in fruits: 253 | print(fruit) 254 | 255 | print("length of list", len(fruits)) 256 | 257 | # while loop 258 | index = 0 259 | while index < len(fruits): 260 | print(fruits[index]) 261 | index += 1 262 | 263 | 264 | # list functions examples: 265 | list1 = [1, 9, 11] 266 | 267 | print(len(list1)) # find length of list - total element count 268 | print(min(list1)) # find min value in list 269 | print(max(list1)) # find max value in list 270 | print(sum(list1)) # sum of all list elements 271 | 272 | 273 | # complete the assignment-6 :) 274 | 275 | -------------------------------------------------------------------------------- /Chap-17 Tuple/Python Notes by Rishabh Mishra Chap-17 Tuple.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-17 Tuple/Python Notes by Rishabh Mishra Chap-17 Tuple.pdf -------------------------------------------------------------------------------- /Chap-17 Tuple/tuples.py: -------------------------------------------------------------------------------- 1 | # Tuples in Python 2 | 3 | my_tuple = (1,2,3) 4 | print(my_tuple) 5 | print(type(my_tuple)) 6 | 7 | # create tuples 8 | # using parenthesis 9 | my_tuple = (1,2,3) 10 | print(my_tuple) 11 | print(type(my_tuple)) 12 | 13 | my_tuple1 = (1, "Madhav", True, 3.15) 14 | print(my_tuple1) 15 | 16 | #2. without parenthesis 17 | tuple1 = 1,2,3 18 | print(tuple1) 19 | print(type(tuple1)) 20 | 21 | # tuple constructor 22 | tuple2 = tuple((1,5,9)) 23 | print(type(tuple2)) 24 | print(tuple2) 25 | 26 | list1 = [1,2,3] 27 | new_tuple = tuple(list1) 28 | print(new_tuple) 29 | 30 | # create a single element 31 | a = ("a",) # comma add 32 | print(type(a)) 33 | 34 | # access tuple - indexing 35 | 36 | fruits = ('apple', 'mango', 'cherry') 37 | 38 | print(fruits[0]) 39 | 40 | print(fruits[-1]) 41 | 42 | # tuple slicing 43 | new_tuple = (10, 20, 30, 40, 50) 44 | 45 | print(new_tuple[0::3]) 46 | 47 | 48 | # tuple operations 49 | # concatenate - join tuples 50 | tuple1 = (1,2,3) 51 | tuple2 = ('a', 'b') 52 | 53 | tuple3 = tuple1 + tuple2 54 | print(tuple3) 55 | 56 | # repetitive 57 | tuple2 = (1,2,3) * 3 58 | 59 | print(tuple2) 60 | 61 | # checking a element in a tuple 62 | tuple22 = (1,2,3) 63 | print(1 in tuple22) 64 | 65 | # tuple iteration 66 | # for loop 67 | fruits = ('apple', 'mango', 'cherry') 68 | 69 | for i in fruits: 70 | print(i) 71 | 72 | # while loop 73 | i = 0 74 | while i < len(fruits): 75 | print(fruits[i]) 76 | i += 1 77 | 78 | 79 | 80 | # tuple methods 81 | color = ('blue', 'green', 'orange', 'blue') 82 | 83 | # count 84 | print(color.count('green')) 85 | 86 | # index 87 | print(color.index('blue')) 88 | 89 | # tuple functions 90 | 91 | numbers = (2, 3, 1, 4) 92 | 93 | #len 94 | print(len(numbers)) 95 | # sum 96 | print(sum(numbers)) 97 | # min, max 98 | print(min(numbers)) 99 | print(max(numbers)) 100 | 101 | # sort 102 | a = sorted(numbers) # tuple is now list 103 | numbers_sorted = tuple(a) 104 | print(numbers_sorted) 105 | 106 | # tuple pack and unpack 107 | 108 | a = "Madhav" 109 | b = 21 110 | c = "Engineer" 111 | 112 | tuple_pack = a,b,c 113 | print(tuple_pack) 114 | 115 | name, age, profession = tuple_pack 116 | print("Name is", name) 117 | print(age) 118 | print(profession) 119 | 120 | 121 | # tuple modification 122 | tuple_numbers = (10, 20, 30) 123 | 124 | # tuple_numbers[0] = 100 # error 125 | 126 | # how to mutate/modify tuple 127 | list_numbers = list(tuple_numbers) 128 | print(list_numbers) 129 | 130 | list_numbers[0] = 100 131 | print(list_numbers) 132 | 133 | tuple_numbers = tuple(list_numbers) 134 | print(tuple_numbers) 135 | # hw - try append, remove, etc method 136 | 137 | 138 | -------------------------------------------------------------------------------- /Chap-18 Sets/Python Notes by Rishabh Mishra Chap-18 Set.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-18 Sets/Python Notes by Rishabh Mishra Chap-18 Set.pdf -------------------------------------------------------------------------------- /Chap-18 Sets/sets.py: -------------------------------------------------------------------------------- 1 | # Sets in Python 2 | 3 | # charaterstics of set 4 | #1. unique values/items 5 | #2. unordered - no indexing 6 | #3. mutable- add/remove elements 7 | #4. Immuatable elements - replace/modify existing elements 8 | 9 | # create set using curly braces 10 | my_set = {1,2,3} 11 | print(my_set) 12 | print(type(my_set)) 13 | 14 | # create set using set constructor 15 | my_set2 = set([4,5,6]) 16 | print(my_set2) 17 | 18 | # set operations 19 | #adding elements 20 | numbers = {1,2,3,4} 21 | numbers.add(100) 22 | print(numbers) 23 | 24 | # removing elements 25 | #remove 26 | fruits = {'apple', 'mango', 'banana'} 27 | # fruits.remove('banana') # if element not present show error 28 | print(fruits) 29 | 30 | #discard 31 | fruits.discard('apple') # doesn't show error 32 | print(fruits) 33 | 34 | 35 | # Set Methods 36 | #1. union - combine elements from 2 sets 37 | set1 = {1,2,3} 38 | set2 = {3,4,5} 39 | union_set = set1.union(set2) 40 | # print(union_set) 41 | 42 | # union alternative 43 | union_set2 = set1 | set2 44 | # print(union_set2) 45 | 46 | #2. Intersection - common elements 47 | set1 = {1,2,3,4} 48 | set2 = {3,4,5} 49 | inter_set = set1.intersection(set2) 50 | # print(inter_set) 51 | 52 | # intersection alternative 53 | inter_set2 = set1 & set2 54 | # print(inter_set2) 55 | 56 | #3. Difference - element present in first set only but not in second set 57 | set1 = {1,2,3,4} 58 | set2 = {3,4,5} 59 | diff_set = set1.difference(set2) 60 | # print(diff_set) 61 | 62 | # Difference alternative 63 | diff_set2 = set1 - set2 64 | # print(diff_set2) 65 | 66 | #4. Symmertic Difference - element in either set but not in both 67 | set1 = {1,2,3,4} 68 | set2 = {3,4,5,6} 69 | sdiff_set = set1.symmetric_difference(set2) 70 | # print(sdiff_set) 71 | 72 | # Symm Diff alternative 73 | sdiff_set2 = set1 ^ set2 74 | # print(sdiff_set2) 75 | 76 | 77 | # Set Iterations 78 | # for loop 79 | numbers = {1,2,3,4,5} 80 | for i in numbers: 81 | print(i) 82 | 83 | # while loop - doesn't support 84 | 85 | 86 | # Set compreshesion 87 | squares = {x**3 for x in range(1,6)} 88 | print(squares) 89 | -------------------------------------------------------------------------------- /Chap-19 Dictionary/Python Notes by Rishabh Mishra Chap-19 Dictionary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-19 Dictionary/Python Notes by Rishabh Mishra Chap-19 Dictionary.pdf -------------------------------------------------------------------------------- /Chap-19 Dictionary/dictionary.py: -------------------------------------------------------------------------------- 1 | # Dictionary in Python 2 | 3 | #syntax: 4 | # my_dict = {'key1':'value1', 'key2':'value2', ...} 5 | 6 | #Methods to create dictionary 7 | # method-1 create dictionary using curly braces 8 | cohort = {'course':'Python', 9 | 'Instructor':'Rishabh Mishra', 10 | 'Level': 'Benginner'} 11 | 12 | print(cohort) 13 | print(type(cohort)) 14 | 15 | # Method-2 using dict() constructor 16 | person = dict(name= 'Madhav', age=20, grade = 'A') 17 | print(person) 18 | print(type(person)) 19 | 20 | # Method-3 using list of tuples 21 | person2 = dict([('name', 'Madhav'), ('age', 20), ('city', 'Mathura')]) 22 | print(person2) 23 | print(type(person2)) 24 | 25 | # Access dictionary values 26 | student = { 27 | 1: 'Class-X', 28 | 'name': 'Madhav', 29 | 'grade': 'A', 30 | 'city': 'Mathura' 31 | } 32 | 33 | print(student) 34 | print(type(student)) 35 | 36 | print(student['name']) 37 | print(student['grade']) 38 | 39 | 40 | # Dictionary Methods 41 | student = { 42 | 1: 'Class-X', 43 | 'name': 'Madhav', 44 | 'grade': 'A', 45 | 'city': 'Mathura' 46 | } 47 | 48 | # keys 49 | print(student.keys()) 50 | 51 | # values 52 | print(student.values()) 53 | 54 | # items 55 | print(student.items()) 56 | 57 | # get 58 | print(student['name']) 59 | print(student.get('email', 'Nahi hai')) 60 | 61 | 62 | # Add/modify items in dictionary 63 | student = { 64 | 'name': 'Madhav', 65 | 'grade': 'A', 66 | 'city': 'Mathura' 67 | } 68 | 69 | # add item - assign operator 70 | student['email'] = 'madhav@example.com' 71 | print(student) 72 | 73 | # modify/replace item - assign operator 74 | student['grade'] = 'A+' 75 | print(student) 76 | 77 | # remove items 78 | # del to remove item 79 | del student['grade'] 80 | print(student) 81 | 82 | # pop method 83 | var1 = student.pop('email') 84 | print(var1) 85 | print(student) 86 | 87 | 88 | # dictionary iteration 89 | student = { 90 | 'name': 'Madhav', 91 | 'grade': 'A', 92 | 'city': 'Mathura' 93 | } 94 | 95 | # loop through keys 96 | for keys in student: 97 | print(keys) 98 | 99 | # loop through values 100 | for value in student: 101 | print(student[value]) 102 | 103 | # using .values() method 104 | for value in student.values(): 105 | print(value) 106 | 107 | # loop through both key-value pair 108 | for keys,value in student.items(): 109 | print(keys, value) 110 | 111 | 112 | # Nested dictionary 113 | 114 | main_student = { 115 | 116 | 'student1' : {'name': 'Madhav', 'age': 20}, 117 | 'student2' : {'name': 'Keshav', 'age': 25, 'grade': 'A'} 118 | } 119 | 120 | print(main_student) 121 | 122 | # access value 123 | print(main_student['student1']) 124 | 125 | print(main_student['student1']['name']) 126 | print(main_student['student2']['grade']) 127 | 128 | 129 | # Dictionary comprehension 130 | 131 | # syntax 132 | # new_dict = 133 | # {key_exp : value_exp for item in iterable if condition} 134 | 135 | my_dict = {x:x+x for x in range(1,6)} 136 | 137 | print(my_dict) 138 | 139 | 140 | # Note: Solve Assignment-6 to practice dictionary questions :) -------------------------------------------------------------------------------- /Chap-2 Python Setup/Python Notes by Rishabh Mishra-Chap02-PythonSetup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-2 Python Setup/Python Notes by Rishabh Mishra-Chap02-PythonSetup.pdf -------------------------------------------------------------------------------- /Chap-20 OOPs/Python Notes by Rishabh Mishra Chap-20 OOPs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-20 OOPs/Python Notes by Rishabh Mishra Chap-20 OOPs.pdf -------------------------------------------------------------------------------- /Chap-20 OOPs/oops.py: -------------------------------------------------------------------------------- 1 | # OOPs in Python 2 | # OOP- Object Oriented Programming 3 | 4 | # using list - creating student records 5 | # student details 6 | student_1 = ['Madhav', 10] # Name, Grade 7 | student_2 = ['Vishakha', 12] 8 | student_3 = 'Keshav' 9 | 10 | student_1.append('A') 11 | print(student_1) 12 | print(f'{student_1[0]} is in class {student_1[1]}') 13 | print(f'{student_2[0]} is in class {student_2[1]}') 14 | 15 | 16 | # using OOPs- creating student records 17 | 18 | # class - blueprint or template 19 | # __init__ method - constructor, value initialize - fix 20 | # self parameter - reference or connection build btw class and object - fix 21 | class Student: # student class 22 | def __init__(self, name, grade, percentage): # method 23 | self.name = name # attribute 24 | self.grade = grade # attribute 25 | self.percentage = percentage # attribute 26 | 27 | def student_details(self): # method 28 | print(f"{self.name} is in class {self.grade}, with {self.percentage}%") 29 | 30 | # object - instance of class 31 | student1 = Student('Madhav', 11, 96) 32 | print(student1.name, student1.grade) 33 | 34 | student2 = Student('Vishakha', 12, 99) 35 | print(student2.name, student2.grade) 36 | 37 | print(student1.percentage) 38 | student1.student_details() 39 | student2.student_details() 40 | 41 | print(student1.__dict__) 42 | 43 | # modify object property 44 | print(student1.percentage) 45 | student1.percentage = 100 # modify 46 | print(student1.percentage) 47 | 48 | # delete object property 49 | print(student1.__dict__) 50 | del student1.percentage 51 | print(student1.__dict__) 52 | 53 | # delete object 54 | del student1 55 | print(student1) 56 | 57 | 58 | 59 | # class - blueprint or template 60 | class Student: # student class 61 | def __init__(self, name, grade, percentage, team): # method 62 | self.name = name # attribute 63 | self.grade = grade # attribute 64 | self.percentage = percentage # attribute 65 | self.team = team 66 | 67 | def student_details(self): # method 68 | print(f"{self.name} is in class {self.grade}, with {self.percentage}% and is in team {self.team}") 69 | 70 | team1 = 'A' 71 | team2 = 'B' 72 | 73 | # object - instance of class 74 | student1 = Student('Madhav', 11, 96, team1) 75 | # print(student1.name, student1.grade) 76 | 77 | student2 = Student('Vishakha', 12, 99, team2) 78 | # print(student2.name, student2.grade) 79 | 80 | # print(student2.team) 81 | student1.student_details() 82 | student2.student_details() 83 | 84 | 85 | 86 | # 4 features in OOPs 87 | # Abstraction 88 | # Encapsulation 89 | # Inheritance 90 | # Polymorphism 91 | 92 | 93 | # Abstraction 94 | # hiding unnecesary deatils from users through class, methods 95 | 96 | class Student: # student class 97 | def __init__(self, name, grade, percentage): 98 | self.name = name # attribute 99 | self.grade = grade 100 | self.percentage = percentage 101 | 102 | def student_details(self): # method - abstraction 103 | print(f"{self.name} is in class {self.grade}, with {self.percentage+2}%") # hidden from users 104 | 105 | # object - instance of class 106 | student1 = Student('Madhav', 11, 96) 107 | student2 = Student('Vishakha', 12, 97) 108 | 109 | student2.student_details() 110 | 111 | 112 | # Encapsulation 113 | # Restrict access to certain attributes or methods to protect data and enforce controlled access 114 | 115 | class Student: # student class 116 | def __init__(self, name, grade, percentage): 117 | self.name = name # attribute 118 | self.grade = grade 119 | self.__percentage = percentage # double underscore limits access 120 | 121 | def get_percentage(self): 122 | return self.__percentage 123 | 124 | def student_details(self): # method 125 | print(f"{self.name} is in class {self.grade}, with {self.percentage}%") 126 | 127 | # object - instance of class 128 | student1 = Student('Madhav', 11, 96) 129 | student2 = Student('Vishakha', 12, 97) 130 | 131 | print(student1.__percentage) # error 132 | print(student1.percentage) # error 133 | print(student2.get_percentage()) 134 | 135 | 136 | # Inheritance 137 | # allows one class (child) to reuse the prop and methods of another class (parent). 138 | 139 | # parent class - baap 140 | class Student: # student class 141 | def __init__(self, name, grade, percentage): 142 | self.name = name # attribute 143 | self.grade = grade 144 | self.percentage = percentage 145 | 146 | def student_details(self): # method 147 | print(f"{self.name} is in class {self.grade}, with {self.percentage}%") 148 | 149 | # object - instance of class 150 | student1 = Student('Madhav', 11, 96) 151 | student2 = Student('Vishakha', 12, 99) 152 | 153 | # child class - beta 154 | class GraduateStudent(Student): # Graduatestudent child class inherit prop and methods from Student Parent class 155 | def __init__(self, name, grade, percentage, stream): # old parameters from parent class and new parameters in child class 156 | super().__init__(name, grade, percentage) # call parent class init 157 | self.stream = stream # new attribute in child class 158 | 159 | def student_details(self): 160 | super().student_details() # method inherit from parent class 161 | print(f'Stream is {self.stream}') 162 | 163 | # object 164 | Grad_Student1 = GraduateStudent('Keshav', 12, 96, 'PCM') 165 | print(Grad_Student1.stream) 166 | 167 | Grad_Student1.student_details() 168 | 169 | 170 | # Polymorphism 171 | # allows methods in difft classes to have same name but difft behaviour depending on objects 172 | 173 | class Student: # student class 174 | def __init__(self, name, grade, percentage): 175 | self.name = name # attribute 176 | self.grade = grade 177 | self.percentage = percentage 178 | 179 | def student_details(self): # method 180 | print(f"{self.name} is in class {self.grade}, with {self.percentage}%") 181 | 182 | # object - instance of class 183 | student1 = Student('Madhav', 11, 96) 184 | student2 = Student('Vishakha', 12, 99) 185 | 186 | # child class 187 | class GraduateStudent(Student): 188 | def __init__(self, name, grade, percentage, stream): 189 | super().__init__(name, grade, percentage) 190 | self.stream = stream 191 | 192 | def student_details(self): # method 193 | # print(f'{self.name} is in class {self.grade}, with {self.percentage}% and from stream {self.stream}') 194 | print('same method with difft o/p') 195 | 196 | # object - Student class 197 | student1 = Student('Madhav', 11, 96) 198 | 199 | # object - GraduateStudent class 200 | Grad_Student1 = GraduateStudent('Keshav', 12, 96, 'PCM') 201 | 202 | student1.student_details() 203 | Grad_Student1.student_details() 204 | 205 | # download notes for defintions and more examples -------------------------------------------------------------------------------- /Chap-21 Modules/Python Notes by Rishabh Mishra Chap-21 Modules.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-21 Modules/Python Notes by Rishabh Mishra Chap-21 Modules.pdf -------------------------------------------------------------------------------- /Chap-21 Modules/module.py: -------------------------------------------------------------------------------- 1 | # Modules in Python 2 | # single py file 3 | 4 | # create a module mymodule.py file 5 | # use mymodule file 6 | 7 | import mymodule 8 | mymodule.say_hello('Madhav') 9 | mymodule.say_bye('Rishabh') 10 | 11 | # import/use specific part of code 12 | from mymodule import person1 13 | print(person1['age']) 14 | 15 | # package: collection modules/py files + __init__.py 16 | 17 | # library: collection of modules and packages 18 | # in-built lib 19 | import math 20 | 21 | A = 36 22 | print(math.sqrt(A)) 23 | 24 | # import specific function from lib 25 | from math import factorial 26 | B = 4 27 | print(factorial(B)) 28 | 29 | # installed new/external modules/lib 30 | # pip install 31 | import pandas as pd 32 | import seaborn as sb 33 | -------------------------------------------------------------------------------- /Chap-21 Modules/mymodule.py: -------------------------------------------------------------------------------- 1 | # creat code to use in another py file 2 | 3 | person1 = {'name': 'Keshav', 'age': 16} 4 | 5 | def say_hello(name): 6 | return print(f"Hello {name}, Kaise ho?") 7 | 8 | def say_bye(name): 9 | return print(f"Bye {name}, takecare!") 10 | -------------------------------------------------------------------------------- /Chap-22 File Handling/Python Notes by Rishabh Mishra Chap-22 File Handling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-22 File Handling/Python Notes by Rishabh Mishra Chap-22 File Handling.pdf -------------------------------------------------------------------------------- /Chap-22 File Handling/file_handling.py: -------------------------------------------------------------------------------- 1 | # File Handling - place the example txt files out of this 'file-handling' folder 2 | # mode: r - read, w - write, a - append 3 | 4 | # open file 5 | file = open('example.txt', 'r') # read mode 6 | 7 | # # read file 8 | file = open('example.txt', 'r') 9 | content = file.read() # read entire data 10 | print(content) 11 | file.close() # best practice 12 | 13 | file = open('example.txt', 'r') 14 | content = file.readline() # read first line 15 | print(content) 16 | file.close() 17 | 18 | file = open('example2.txt', 'r') 19 | content = file.readlines() # list entire data 20 | print(content) 21 | file.close() 22 | 23 | 24 | # write to a file 25 | file = open('example2.txt', 'w') # write mode - overwrite 26 | file.write("Namaste, kasie ho?") 27 | file.close() 28 | 29 | file = open('example2.txt', 'a') # append mode - incremental write 30 | file.write("\nAgain Acha hu.") 31 | file.close() 32 | 33 | 34 | # close a file 35 | # using with statement 36 | with open('example2.txt', 'r') as file: 37 | content = file.readline() 38 | print(content) 39 | 40 | # exceptional handling when closing a file 41 | try: 42 | file = open('example2.txt', 'r') 43 | content = file.read() 44 | print(content) 45 | finally: 46 | file.close() 47 | 48 | # HW: How can you handle multiple exceptions while performing operations on a file? 49 | # error example: FileNotFound, ValueError, etc -------------------------------------------------------------------------------- /Chap-3 First Program/Python Notes by Rishabh Mishra-Chap03-FirstProgram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-3 First Program/Python Notes by Rishabh Mishra-Chap03-FirstProgram.pdf -------------------------------------------------------------------------------- /Chap-3 First Program/first.py: -------------------------------------------------------------------------------- 1 | print("Hello World") 2 | # This is how we add a comment in python 3 | 4 | # This is a variable 5 | a = 5 6 | print(a) 7 | 8 | # This is a variable 9 | Instructor = 'Rishabh Mishra' 10 | print("Python by", Instructor, sep='-') 11 | 12 | # python as a calculator 13 | print("5+3") 14 | print(5+3) 15 | 16 | b = 10 17 | c = 20 18 | print(b+c) 19 | print(c/b) 20 | print(c*b) -------------------------------------------------------------------------------- /Chap-3 First Program/firstcode.py: -------------------------------------------------------------------------------- 1 | print("Welcome to the Python course by Rishabh Mishra") -------------------------------------------------------------------------------- /Chap-4 Variables/Python Notes by Rishabh Mishra-Chap04-Variables.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-4 Variables/Python Notes by Rishabh Mishra-Chap04-Variables.pdf -------------------------------------------------------------------------------- /Chap-4 Variables/variables.py: -------------------------------------------------------------------------------- 1 | # Variables in python 2 | a = 1 # integer number 3 | print(a) 4 | 5 | b = 1.1357101 # decimal number 6 | print(b) 7 | 8 | c = "Madhav" # word/sentence- use quotes 9 | print(c) 10 | 11 | Rishabh = 26 # declare a varibale using varibale 12 | d = Rishabh 13 | print(d) 14 | 15 | x = 10 # adding a number to a variable 16 | print(x+1) 17 | 18 | p,q,r = 11,12,13 # assign multiple varibales 19 | print(p,q,r) 20 | 21 | # ways to declare a variable name 22 | MyName = "Madhav" # pascal case 23 | myName = "Madhav" # camel case 24 | myname = "Madhav" # flat case 25 | my_name = "Madhav" # snake case 26 | 27 | # rules to declare a varibales 28 | # 1. varibale name must start with: letter or _ 29 | _my_name = "Madhav" 30 | print(_my_name) 31 | # myname = "Madhav" 32 | 33 | # 2. Varibale name can contain: letter, numbers, underscore (_) 34 | my_name1 = "Madhav" 35 | r1 = 26 36 | _1 = 1 37 | 38 | # 3. Variables are case sensitive 39 | myname = "RishabhMishra" 40 | print(myName) 41 | 42 | # 4. variables names can't be a reserved word 43 | # for = 10 # for is a reserved word in python 44 | -------------------------------------------------------------------------------- /Chap-5 Data Types/Python Notes by Rishabh Mishra-Chap05-DataTypes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-5 Data Types/Python Notes by Rishabh Mishra-Chap05-DataTypes.pdf -------------------------------------------------------------------------------- /Chap-5 Data Types/datatypes.py: -------------------------------------------------------------------------------- 1 | # data types in python 2 | a = 1 3 | b = 1 4 | print(a+b) 5 | print(type(a)) # checking data type: integer 6 | 7 | c = "1" 8 | d = "1" 9 | print(c+d) 10 | print(type(c)) # checking data type: string 11 | 12 | # basic data types in python: 13 | #1. Numeric 14 | a1 = 1 #1a. integer 15 | a2 = 1.5 #1b. float 16 | print(type(a2)) 17 | a3 = complex(3,5) #1c. complex 18 | print(type(a3)) 19 | 20 | #2. Sequence 21 | b1 = "Madhav" #2a. string 22 | b11 = '26' 23 | print(type(b1)) 24 | b2 = [1,4,7,26,108,'Madhav'] #2b. list 25 | print(type(b2)) 26 | b3 = (1,4,7,26,108,'Madhav') #2c. tuple 27 | print(type(b3)) 28 | 29 | #3. Dictionary 30 | my_dictionary = {'name': 'Rishabh', 'age': 26, 'city': 'Prayagraj'} 31 | print(type(my_dictionary)) 32 | 33 | #4. Sets 34 | my_sets = {1,4,7,26,108,'Madhav'} 35 | print(type(my_sets)) 36 | 37 | #5. Boolean 38 | bool1 = True 39 | bool2 = False 40 | print(type(bool1)) 41 | 42 | #6. Binary 43 | # bytes, bytearray, memoryview 44 | byte1 = b"Madhav" 45 | print(type(byte1)) 46 | -------------------------------------------------------------------------------- /Chap-6 Type Casting/Python Notes by Rishabh Mishra-Chap06-TypeCasting.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-6 Type Casting/Python Notes by Rishabh Mishra-Chap06-TypeCasting.pdf -------------------------------------------------------------------------------- /Chap-6 Type Casting/casting.py: -------------------------------------------------------------------------------- 1 | # casting in python 2 | 3 | a = 1 # int type 4 | print(type(a)) 5 | 6 | b = "1" # str type 7 | print(type(b)) 8 | 9 | c = int(b) # convert str to int type 10 | print(type(c)) 11 | 12 | print(a+int(b)) 13 | 14 | # all str type can't be casted into numerical type 15 | # name = "Madhav" 16 | # newname = int(name) 17 | 18 | # all numerical type can be cast into str 19 | mynum = 26 # int type 20 | mynum2 = str(mynum) # convert int to str type 21 | print(type(mynum2)) 22 | 23 | f1 = 22.56 # float type 24 | f2 = int(f1) # convert float to int type 25 | print(f2) 26 | print(type(f2)) 27 | 28 | in1 = 26 29 | print(type(float(in1))) 30 | 31 | # type casting types: 32 | 33 | # 1. implicit type casting - python automatically convert data type 34 | var1 = 10 #int type 35 | var2 = 15.5 #float type 36 | var3 = var1+var2 37 | print(var3) 38 | print(type(var3)) 39 | 40 | # 2. explicit type casting - programmer need to manually convert data type 41 | int_num = 101 # int type 42 | str_num = str(int_num) # convert to str type 43 | print(type(str_num)) 44 | 45 | a0 = bool(0) # boolean type - False 46 | print(a0) 47 | print(type(a0)) 48 | 49 | a1 = bool(1) # boolean type - True 50 | print(a1) 51 | print(type(a1)) -------------------------------------------------------------------------------- /Chap-7 Input Function/Python Notes by Rishabh Mishra Chap-07-Input Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-7 Input Function/Python Notes by Rishabh Mishra Chap-07-Input Function.pdf -------------------------------------------------------------------------------- /Chap-7 Input Function/input.py: -------------------------------------------------------------------------------- 1 | # input function in python 2 | 3 | a = input() 4 | print(a) 5 | 6 | a = input() 7 | print(a+a) 8 | 9 | a = input() 10 | print(int(a)+int(a)) 11 | # input function always reads input value as a string 12 | 13 | name = input("Enter your name: ") 14 | print(f"Welcome {name} to the Python Tutorial Series") 15 | 16 | age = input("Enter your age: ") 17 | # print(f"Ohh you're just {age}!") 18 | print(f"So next year you will be {int(age)+1}!") 19 | 20 | # multple input from user 21 | # input from user to add two number and print result 22 | x = input("Enter first number: ") 23 | y = input("Enter second number: ") 24 | print(f"Sum of {x} & {y} is {int(x) + int(y)}") 25 | 26 | # HW: write a program to input student name and marks of 3 subjects. 27 | # And print name and percentage in output. 28 | 29 | # share solution in comments or Linkedin - @rishabhnmishra -------------------------------------------------------------------------------- /Chap-8 Operators/Python Notes by Rishabh Mishra Chap-08-Operators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-8 Operators/Python Notes by Rishabh Mishra Chap-08-Operators.pdf -------------------------------------------------------------------------------- /Chap-8 Operators/operators.py: -------------------------------------------------------------------------------- 1 | # operators 2 | 3 | # 1. Arithmetic Operators 4 | a = 5 5 | b = 3 6 | print(a+b) # addition operator 7 | print(a-b) # substraction operator 8 | print(a*b) # multiplication operator 9 | print(a%b) # modulus operator 10 | 11 | # 2. Comparison operators - output is a boolean value (T/F) 12 | a = 5 13 | b = 3 14 | print(a > b) #greater than operator 15 | print(a < b) #less than operator 16 | print(a == b) # equal operator 17 | print(a != b) # not equal operator 18 | 19 | # 3. Assignment Operators 20 | a = 5 # assignment Operator 21 | 22 | # 4. Logical Operators - and, or, not 23 | # Rule for 'and' operator 24 | # 1. True + True = True 25 | # 2. True + False = False 26 | # 3. False + False = False 27 | 28 | a = 10 29 | b = 20 30 | print(a>10 and b<10) # and operator 31 | print(a==10 and b==20) 32 | print(a==10 or b<10) # or operator 33 | 34 | # Rule for 'or' operator 35 | True + False = True 36 | 37 | # 'not' operator 38 | print(not(a==10 and b==20)) 39 | 40 | # 5. Identity operators - is, is not 41 | x = [1,2,3] 42 | y = x 43 | z = [1,2,3] 44 | print(x is y) # is operator 45 | print(x is z) 46 | 47 | print(x is not z) # is not operator 48 | 49 | # 6. Membership operators - in, not in 50 | my_list = ['apple', 'orange', 'watermelon'] 51 | print('apple' in my_list) # in operator 52 | print('apple2' in my_list) 53 | print('apple2' not in my_list) # not in operator 54 | 55 | # # 7. Bitwise operators - AND &, OR |, XOR ^, NOT ~, etc 56 | a = 5 # 5 in binary- 0101 57 | b = 3 # 3 in binary- 0011 58 | print(a & b) # 1 in binary- 0001 59 | 60 | # Rule for AND '&' operator 61 | # 1. True + True = True 62 | # 2. True + False = False 63 | # 3. False + False = False 64 | 65 | # Rule for OR '|' operator 66 | # True + False = True -------------------------------------------------------------------------------- /Chap-9 Conditional Statements/Python Notes by Rishabh Mishra Chap09-Conditional Statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rishabhnmishra/python_tutorial_notes/5d7e774fbaa1ead6ba52be5e305bcead2f6ff89c/Chap-9 Conditional Statements/Python Notes by Rishabh Mishra Chap09-Conditional Statements.pdf -------------------------------------------------------------------------------- /Chap-9 Conditional Statements/if_else.py: -------------------------------------------------------------------------------- 1 | # conditional statement in Python 2 | 3 | # 1. if statement 4 | # if statement works only for True condition 5 | 6 | a = 26 7 | b = 108 8 | if b > a: # true 9 | print("b is greater than a") 10 | 11 | a = 260 12 | b = 108 13 | if b > a: #false - no output 14 | print("b is greater than a") 15 | 16 | age = int(input("Enter your age: ")) 17 | if age > 19: 18 | print("Your are an adult") 19 | 20 | 21 | # 2. if-else statement 22 | # else handles False condition 23 | 24 | age = int(input("Enter your age: ")) 25 | if age > 19: 26 | print("Your are an adult") 27 | else: 28 | print("You are not an adult") 29 | 30 | temp = 30 31 | 32 | if temp < 25: 33 | print("It's a cool day") 34 | else: 35 | print("It's a hot day") 36 | 37 | 38 | # 3. if-elif-else statement 39 | # multiple conditions 40 | 41 | marks = int(input("Enter your marks-100: ")) 42 | 43 | if marks >= 90: 44 | print("Grade: A+") 45 | elif marks >= 80: 46 | print("Grade: A") 47 | elif marks >= 70: 48 | print("Grade: B") 49 | else: 50 | print("Grade: C") 51 | 52 | 53 | # 4. Nested if-else statement: 54 | # if-else inside if-else statement 55 | # multiple conditions depend on each other 56 | 57 | # Q: positive, negative & zero. Postive - even/odd 58 | number = int(input("Enter a number: ")) 59 | 60 | if number > 0: #checking positive number 61 | if number % 2 == 0: 62 | print("This is a even number") 63 | else: 64 | print("This is an odd number") 65 | else: 66 | if number == 0: # checking zero value 67 | print("This is zero") 68 | else: 69 | print("This is a negative number") 70 | 71 | 72 | # 5. Conditional Expressions (ternary operator) 73 | 74 | age = 16 75 | status = "Major" if age >= 18 else "Minor" 76 | print(status) -------------------------------------------------------------------------------- /Final Project- Password Checker/password_checker.py: -------------------------------------------------------------------------------- 1 | # password strength checker 2 | 3 | import re 4 | 5 | # password strength check conditions: 6 | # min 8 chars, digit, uppercase, lowercase, special char 7 | 8 | def check_password_strength(password): 9 | """ 10 | Function to check the strength of a password. 11 | """ 12 | if len(password) < 8: 13 | return "Weak: Password must be at least 8 characters long." 14 | 15 | if not any(char.isdigit() for char in password): 16 | return "Weak: Password must include at least one number." 17 | 18 | if not any(char.isupper() for char in password): 19 | return "Weak: Password must include at least one uppercase letter." 20 | 21 | if not any(char.islower() for char in password): 22 | return "Weak: Password must include at least one lowercase letter." 23 | 24 | if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password): 25 | return "Medium: Add special characters to make your password stronger." 26 | 27 | return "Strong: Your password is secure!" 28 | 29 | def password_checker(): 30 | """ 31 | Main function to take user input and check password strength. 32 | """ 33 | print("Welcome to the Password Strength Checker!") 34 | 35 | while True: 36 | password = input("\nEnter your password (or type 'exit' to quit): ") 37 | 38 | if password.lower() == "exit": 39 | print("Thank you for using the Password Strength Checker! Goodbye!") 40 | break 41 | 42 | result = check_password_strength(password) 43 | print(result) 44 | 45 | 46 | # Run the password checker 47 | if __name__ == "__main__": 48 | password_checker() 49 | -------------------------------------------------------------------------------- /Project-1 Calculator/calculator.py: -------------------------------------------------------------------------------- 1 | # python program to create a simple calculator 2 | 3 | # 3 steps to build calculator program 4 | # 1. functions for operations 5 | # 2. user input 6 | # 3. print result 7 | 8 | # step-1: create functions: 9 | # Function to add two numbers 10 | def add(num1,num2): 11 | return num1 + num2 12 | 13 | # Function to substract two numbers 14 | def sub(num1,num2): 15 | return num1 - num2 16 | 17 | # Function to multiply two numbers 18 | def multiply(num1,num2): 19 | return num1 * num2 20 | 21 | # Function to divide two numbers 22 | def divide(num1,num2): 23 | return num1 / num2 24 | 25 | # Function to average two numbers 26 | def avg(num1,num2): 27 | return (num1 + num2)/2 28 | 29 | #Step-2: user input 30 | print("Please select a operation:\n " \ 31 | "1. Addition\n" \ 32 | "2. Substraction\n" \ 33 | "3. Multiplication\n" \ 34 | "4. Division\n" \ 35 | "5. Average\n") 36 | 37 | select = int(input("Select a operation from 1,2,3,4,5: ")) 38 | 39 | number1 = int(input("Enter first number: ")) 40 | number2 = int(input("Enter second number: ")) 41 | 42 | #Step-3: Print the result 43 | 44 | if select == 1: 45 | print(number1, "+", number2, "= ", \ 46 | add(number1, number2)) 47 | 48 | elif select == 2: 49 | print(number1, "-", number2, "= ", \ 50 | sub(number1, number2)) 51 | 52 | elif select == 3: 53 | print(number1, "*", number2, "= ", \ 54 | multiply(number1, number2)) 55 | 56 | elif select == 4: 57 | print(number1, "/", number2, "= ", \ 58 | divide(number1, number2)) 59 | 60 | elif select == 5: 61 | print("(",number1, "+", number2, ")", "/", "2", "= ", \ 62 | avg(number1, number2)) 63 | 64 | else: 65 | print("Invalid operation! Pls select again!") 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python_tutorial_notes 2 | Complete Python Tutorial for Beginners Notes 3 | 4 | ### Learn more on YouTube Channel: www.youtube.com/playlist?list=PLdOKnrf8EcP384Ilxra4UlK9BDJGwawg9 5 | --------------------------------------------------------------------------------