Python Notes
Python Notes
MACHINE LEARNING:
Subset of AI
Machines – learn itself by seeing and understands and create algorithms own
PYTHON
Text analysis
Statics analysis
Predictive
Diagnostic analysis
Not give 100 percent predictions but you do some predictions (100%)
DIAGNOSTIC ANALYSIS – based on the data it will going to find the root cause
of issue
-programming language
Interpreter is there
Mutable – change
1.LIST []
2. SET {}
3. DICTIONARY {key:value}
LIBRARIES:
1. Numpy
2. Panda
3. RE
4. Matplotlib
NUM:
# commenting
Type – datatype of a
STRING:
“oracle”=’oracle’
Indexing forward 0
Backward-1
A=”ORACLE”
Print(A)
Print(a[-1])
Print(a.lower())
split function:
a=”oracle python”
print(a.split(‘e’))
output:
[‘oracl’,’python’]
It will split whenever they find e in the string and split it to separate words
LIST:
Ordered collection
A[1] -- 20
A[5][1] -- 20
A[1:6] -- [20,30,hi,
Add:
L1.append(2)
Print(l1)
Access : print(l2)
Output: []
L1[1] = 80;
Print(l1)
[10,80,20,……….]
Ordered collection
immutable
T1=(10,20,’hi’,’hello’)
Print(t1)
T1[2] =’oracle’ ---error – you cant change the value once it is created
User input:
Print(a)
A=10
SET :
Unordered
Cant predict
{ } -- denote as set
print (s1)
output: set()
DICTIONARY:
Unordered collection
Key value
10 suganya
D1 ={10: ‘suganya’, ‘a’ : ‘harini’}
Print(d1)
LIST :
Hetrogeneous
ordered collection
a=[10,20,30,'hi','HELLO',[10,20]]
a[1]=20
a[5][0]=20
indexing
TUPLE:
()
SET
duplication of elements not allowed
s1={}=it is not an empty set
s1=set()
unordered collection-
display
you cant perfrom indexing
DICTIONARY
key value
10 suganya
a harini
print(d1[10])
NUMBER-int,float,complex
STRING- forward,backward
LIST-[]=>ordered collection,mutable,indexing
SET=> {}=>SET()=>unordered collection
DICTIONRY=>UC=>{key:value,}
CONTROL STRUCTURE:
When you want to execute multiple times you use this
Eg:
A=10
B=30
If (a>b):
Else:
-------
L1=[1,20,40,46,56]
Print(l1)
Print(i)
l1=[10,20,30,40,30,40]
for i in range(1,5,2):
print(l1[i])
FUNCTIONS:
Def fun(name):
Print(name)
Fun(“suganya”)
Def add():
A=10
B=20
C=A+B
Return c
Def add(a,b)
C=a+b
Return c
Call:
X=10
Y=30
Total=add(x,y)
Def f1(a,b=2) --if I pass b variable it will take and if I don’t pass any
variable for b then the default value 2 will be assigned to b
Print(a+b)
Passing : Print(f1(10,20))
Def f1(name,id):
Print(“hi”,name);
Print(“age”,age);
Passing: print(f1(age=10,name=”sugan”))
Def name(*a): --variable length arguments . if we don’t know how
many no of arguments you have passed then use this to pass any no of
arguments
Eg:
Def name(*a):
For I in a :
Print(i)
Passing: name(10,20,30)
Out:
10
20
30
Print(“%s==%s”, %(a,b))
Out:
Firstname==sugan
Lastname==b
SCOPE OF VARIABLE:
global
eg:
add=lamda x,y:x+y
passing: print(add(1,4))
output: 5
l1=[11,50,60]
l2=list(map(lamda x: x * 2,l1)) -- if
RECURSIVE FUNCTION:
Factorial:
Def fact(x):
If x==1:
Return 1
Else:
Return (x * fact(x-1))
Passing: print(fact(4))
Pop:
A=l1.pop(1) --in pop you passing the index
Print(l1)
Remove:
Delete:
Discard(20) – remove method raise an error if the element not exist and
discard method will not do this
Out=re.match(“a”,”suganya”)
Result=re.search(“world”,text)
Findall(“world”,text)
NUMPY:
Array concept
Homogeneous
Eg:
A1=np.array([1,4,6])
Print(a1)
A1=np.array([3,4,5]),dtype=float or complex)
Print(a1)
Functions:
[0.0.0.0.0]
[1.1.1.1.1]
Np.linespace(0,4,3) --equally split and create an array
[0. 2. 4.]
A2=np.Array([1,5,3,6],[3,5,8,4])
Print(a2)
[:3,:3,:2] --
Print(np.power(a1,a2)) --a1^2
Np.power(a1,2)) -- multiply by 2
print(np.char.add([‘a’,’b’], [‘c’,’d’]))
output : [‘ac’ , ‘bd’] -- first elements will be added in the first list and
second element will be added in the second list
np.char.multiply(‘a’,20)
aaaaaaaaaaaaaaaaaa
np.char.center(‘a’,10,fillchar=’*’))
out: ****a*****
print(np.argsmax(a1))
print(np.sort(a1))
pandas:
series – 1d
dataframe – 2d
PYTHON:
Tuple inside the list access using index by – [][] -> specifying separate
box symbol
List
Extend - [[2,3]] it give multiple values to list and in the nested list
Dictionary :
Delete element by
1. Del dict[1]
2. Dict.pop(3)
3. Dict.clear()
Set:
List:
Common prog:
Prime
Prime below 50
Average
Largest element
Second max
Largest list