Posts

Showing posts from August, 2020

Regular Expressions

                  Regular Expressions Regular expressions is the sequence of charcaters which are used to search for a pattern in a string. In python we have re module which can be used to perform regular expressions task easily. We need to import this module named re like this -  import re To find the any pattern in the given string we can use search() function which will give us the object and in that object contains the information about that searched patern. It will contain whether the patten has been found or not if yes then it contains the span of that pattern i.e. starting and ending index. Remember that it is case sensitive function.  print(re.search("pattern", "searching pattern in text") ) Output: <re.Match object; span=(10, 17), match='pattern'> Now we can use this object take out relevent information like start() function can be used to find the starting index in string where pattern has been found and end()...

NumPy

                    Numpy in Python NumPy means Numeric Python. It is a package in Python which deals with numeric computation and processing of arrays. NumPy makes easy for us to do the numeric computations. Numpy plays a important role in Machine Learning. There are many inbuilt functions in Numpy, you just need to know when and how to use them. Numpy deals with different ranges of int and float data types. Now lets see how to use NumPy and do the mathematical computations. Before using NumPy we have to import it. Generally we use alias while importing the library but it is only optional. Creating Arrays: import numpy as np a1 = np.array([2, 1, 3, 4])    # single dimension array print(a1) Output: [2  1  3  4] a2 = np.array([[1, 2, 1], [2, 1, 2], [1, 2, 3]])   # multi-dimension array print(a2) Output: [[1  2  1]                      ...

OOPs - Inheritance

               Inheritance in Python In OOPs when one class extends or inherit the properties of another class then it is called as Inheritance. The class from which we inherit the property is called Parent class and another one is called as child class. By property we means methods and data.  To inherit parent into child we pass the parent class as a parameter into the child class. Lets see how -  class Animal:          def walking():                    print("Animal walking") class Dog(Animal):          def speak():                    print("Barking") d = Dog() d.speak()      # Barking d.walking()    # Animal walking As we can see that we have not defined the walking function in Dog class but we can still use it because we inherited it from Animal class....