Posts

Showing posts from October, 2020

Decorators in python

Image
Decorators:  Before knowing about the decorators we should have basic knowledge about the functions. Python’s functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions. A decorator is a function that receives another function as argument. The behaviour of the argument function is extended by the decorator without actually modifying it. def calculate_decorator (function_parameter): #receives another function as argument def warp_calculation (cal_num): # wrap the function and extends its behaviour add = function_parameter(cal_num) + 4 print (add) return warp_calculation # return wrapped function def calculation (number): return number # return number calculation = calculate_decorator(calculation) calculation( 3 ) Output:      (or another way as follow) @[decorator_function_name] syntax to specify a decora...

Python class method

Image
Class method: The class method in python class is achieved by using built-in decorator called  @classmethod or  classmethod()  - > By using  class method w e can call the class method  with or without creating an object .   -  > Addition to that we can access all the properties of the class Which means that  class method is bound to a class rather than the objects of that class. Since creating object is not necessary in class method we no need to include self as parameter in methods. However to access all the properties of class we need to include 'cls' as parameter  Note: As self is the reference of object  Using @classmethod in class: class Car: brand = 'Rolls-Royce' fast = 155 @classmethod # create speed class method def speed ( cls ): print ( cls .brand + ' speeds ' , cls .fast , 'mph' ) Car.speed() # with out creating object calling the method obj = Car() # creating object obj.speed() # callin...

Python Static method

Image
  Static Method: The static method in python class is achieved by using built-in decorator called  @staticmethod or  staticmethod() By using static method we  can call the method in class  with or without creating an object .  Which means that  static method is bound to a class rather than the objects of that class. Since creating object is not necessary in static method we no need to include self as parameter in methods. Note: As self is the reference of object Using @staticmethod in class: class Lion: @staticmethod # create static method for portray using decorator def portray (): print ( 'Lion is king of the jungle' ) Lion.portray() # with out creating object calling the method obj = Lion() # creating object obj.portray() # calling the method using object Output: Using staticmethod() in class: class Lion: def portray (): print ( 'Lion is king of the jungle' ) Lion.portray = staticmethod (Lion.portray) # create static meth...

Learn basics of python collection data type (list, tuple, dictionary and set) instantly

    List Tuple Dictionary Set Definition Its a mutable/changeable object and its collection is ordered.   Allow duplicate members   Note: Its changeable/ immutable object.(i.e, able to update,add or remove the list   item) Its a immutable/un changeable   object and its collection is ordered.   Allow duplicate members   Note: Its unchangeable/ immutable object.(i.e, unable to update, add, remove the tuple item)   However, we can   delete items from it. Its a mutable/ changeable   object and its collection is unordered.   No duplicate members   Note: Its changeable/ immutable object.(i.e, able to update,add or remove the dictionary item)     Its   a collection of unordered item.   No duplicate members   Its used to perform mathemat...

Switch frame in selenium python

Image
  What is iframe? Full form of iframe- inline frame The inline frames allow you to display a second, separate webpage within your main webpage. (or) An inline frame is used to embed another html document within the current HTML document. When iframe is used in web application or web page ? Iframe is used to include a third-party widget or content. For example: Facebook like button, a YouTube video, or an advertising section on your website. As the seperate secondary webapge is embedded in to the main web page. It is necessary to move the secondary webapage(i.e. iframe) to find the element in it. How we can move/switch to the secondary webpage or iframe ? Selenium WebDriver provides three ways to switch over the elements in an iframe. By Index By Name or Id By Web Element switch_to_frame(index) (or) switch_to.frame( index ) This method is used to identify a frame with the help of frame id and then switch the focus to that particular frame. Syntax  − driver.switch_to_frame(numer...