PYTHON NOTES


cmath is a mathematical module that is present in python to convert complex numbers to polar numbers
Doubt: why we use * in cmath as *cmath need to know this (it is raised in polar coordinates problem hacker rank) 
                     we use * because it clears the brackets and take the input from spaces of lists

rpartition() function in Python split the given string into three parts. rpartition() start looking for separator from right side, till the separator is found and return a tuple which contains part of the string before the separator, the argument of the string, and the part after the separator
 
In Python 3 we use // for integer division

Since set elements must be hashable, and lists are considered mutable, you cannot add a list to a set.

Try Except in Python
The try block is used to check some code for errors i.e the code inside the try block will execute when there is no error in the program. Whereas the code inside the except block will execute whenever the program encounters some error in the preceding try block.

when we have sorted array and we need comparison we then we will do binary comparison

eval is a built-in- function used in python, eval function parses the expression argument and evaluates it as a python expression. In simple words, the eval function evaluates the “String” like a python expression and returns the result as an integer.


n=input()
for i in range(n):
    x,y,z=map(int,input().split())
    print(x,y,z)
    if x>y>z>50:
        if x>y and x>z:
            print("A")
        elif y>z and y>x:
            print("B")
        elif z>x and z>y:
            print("C")
        else:
            print("NOTA")

What is NumPy?

NumPy is a Python library used for working with arrays.

It also has functions for working in the domain of linear algebra, Fourier transform, and matrices.

NumPy was created in 2005 by Travis Oliphant. It is an open-source project and you can use it freely.

NumPy stands for Numerical Python.


Why Use NumPy?

In Python, we have lists that serve the purpose of arrays, but they are slow to process.

NumPy aims to provide an array object that is up to 50x faster than traditional Python lists.

The array object in NumPy is called ndarray, it provides a lot of supporting functions that make working with ndarray very easy.

Arrays are very frequently used in data science, where speed and resources are very important.

once learn regex and phrase

A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern.

  1. a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.

LOGIC TO GENERATE FIBONACCI SERIES:
print(n1)
       nth = n1 + n2
       # update values
       n1 = n2
       n2 = nth
  1. isalnum() is a built-in Python function that checks whether all characters in a string are alphanumeric. In other words, isalnum() checks whether a string contains only letters or numbers or both. If all characters are alphanumeric, isalnum() returns the value True ; otherwise, the method returns the value False 

@ symbol is a syntactic sugar python provides to utilize decorator , to paraphrase the question, It's exactly about what does decorator do in Python? Put it simple decorator allow you to modify a given function's definition without touch its innermost (it's closure).

Floats are rounded to provide an approximation when excessive precision is unnecessary or unwieldy. For example, the float 1.2345 rounded to the tenths place is 1.2
 
need to learn 
regex



decorators
classes

Python's re. compile() method is used to compile a regular expression pattern provided as a string into a regex pattern object ( re. Pattern ). ... In simple terms, We can compile a regular expression into a regex object to look for occurrences of the same pattern inside various target strings without rewriting it










Comments

Popular posts from this blog

c program notes