Sunday, March 31, 2019

Learning Python - Key Notes Part # 1

1) Strings are immutable in python.

2) Access Substring directly like name1[1:34]

3) Negative range name1[-23] , index from behind

4) list can have different type of data like PHP

5) list allows pop, insert , append, extend and del functions

6) list is mutable but tuple is not.
  names=[] <= list
  names=() <= tuple

*** tuple iteration is faster than list ***

7) set have no sequence.
    names={} <= set
8) memory efficient, one address for one value
a=10
b=a
k=10

id(10)=id(a)=id(b)=id(k)

garbase collection , if no one refering to a value

9) there is no way to create immutable variable. Just declare constants in Uppercase.

10) types
    > None
    > Numeric => int,float, complex,bool
   > list
   > tuple
   > set
  > String
   > Range
   > Dictionary

11) Range ==
   range(1,10)
   range(1,10,2) ==> diff of 2

12) Dictionary
   Key value pair
  d={'k1':'v1','k2':'v2'}

13) uniry operator
  negate == just put -
 p=-q

14) for loop
   for i in x :

15) python function can return multiple values
      def func() :
         x=2
         y=3
         return x,y
16) there is nothing pass by value or reference, it is about mutable vs immutable variables in python.

   int will not change but list will change inside function

17) Keyword arguments can be passed directly
    z=sum(y=12,x=10)
    def sum(x,y):

18) variable length parameters passed as tuple
      z=sum(1,2,3,4,5)
      def sum(*a) :

   *Keyword variable length arguments
    def sum(**a):

   z=sum('x'=1,'y'=2,'c'=3);
19) global variable , use keyword global to tell about it
        a =10
         def f():
             global a;
               a=13

   or use globals() function
          x=globals()['a']
20) anonymous functions (lamnda expressions):
      functions are object in python. One can pass function to another function.
      square==> f= lambda a:a*a
   z= f(4)

21) Filter, Map and Reduce
     filter(lambda x:x%2==0 ,list)
     map(lambda x:x*2, out1)
    reduce(lambda x,y:x+y,out2)


Friday, March 8, 2019

Excel sheet trics

1. Absolute reference

Absolute Reference

See the formula in cell E3 below.
1. To create an absolute reference to cell H3, place a $ symbol in front of the column letter and row number ($H$3) in the formula of cell E3.