You are on page 1of 12

It was created by Guido van Rossum, and

released in 1991.
=>Python is a general purpose, dynamic, high level, interpreted programming and multi paradign
language.

=> Python language was developed by Guido van Rossum. The first version of Python was
released in 1991 from python software foundation. Python is free software and open source Official
Web site : www.python.org (http://www.python.org)

Multi Paradigm => It supports FUnctional programming, Structured or Modular Programming and
Object Oriented Programming

=>Python language is used to develop the different types of application such as stand alone
applications, web applications, scientific applications

Features of Python:

Simple to Learn and Easy to Use =>It is a programmer friendly language . => Uses an elegant
syntax, making the programs write easier.

Object Oriented Programming Language: =>Python supports object oriented features classes
,objects, inheritance etc..

Expressive Language =>Python code is easily understandable.

Platform Independent =>We can develop any application using Python on one platform and we
can run this python code on any platform

#Python is a case sensitive language when dealing with identifiers

#Identifiers can be of any length

#Indentation - Use 4 spaces per indentation level

#Limit all lines to a maximum of 79 characters

#Backslashes may still be appropriate at time

#For example, long, multiple with-statements cannot use implicit continuation

#so backslashes are acceptable

#Camel case, Snakecase and Pascal Case

#CapitalizedWords or CapWords, or CamelCase

#Snake case (or snake_case) is the practice of writing compound words or phrases

#in which the elements are separated with one underscore character

#Pascal Case: UserLoginCount


#In Python a variable can start with _variablename,

#however reduced readability not used in practice

#As Python has no concept of private variables, leading underscores are used

#to indicate variables that must not be accessed from outside the class

#True, False and None are capitalized keywords while the other keywords are in lower case.

Assigning values to multiple variables


a,b,c = 1000, 2000, 3000

result = a+b*c

#Operators with the same precedence are evaluated in "Left to Right" manner

#PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction.

#Note that the precedence order of Division and Multiplication is the same.

#Likewise, the order of Addition and Subtraction is also the same.

#https://www.sanfoundry.com/python-questions-answers-precedence-associativity-2/
(https://www.sanfoundry.com/python-questions-answers-precedence-associativity-2/)

#https://www.sanfoundry.com/python-questions-answers-precedence-associativity-1/
(https://www.sanfoundry.com/python-questions-answers-precedence-associativity-1/)

Spyder, Atom, PyCharm and Jupyter Note


Book
In [7]: python --version

# Single line Comment


#lakshmi

""" Demo for multiline comment


as many comment lines we can add into the
programming"""

"""A variable name must start with a letter or the


underscore character
A variable name cannot start with a number A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive (age, Age and
AGE are three different variables)"""

In [8]: age, name, city =43, "Lakshmi", 'Hyderation'


age

Out[8]: 43

In [9]: name

Out[9]: 'Lakshmi'

In [10]: city

Out[10]: 'Hyderation'

In [ ]: +
-
*
/
%
**

In [12]: 2/5

Out[12]: 0.4

In [2]: 2**2**4
#Left to right Associativity

Out[2]: 65536

In [4]: 25%3

Out[4]: 1

DataSet & Platforms


#Kaggle

#Github

#UCI Machine Learning Repositories

Websites & YouTube Cahnnels for Data Science


Aspirants
#https://towardsdatascience.com/ (https://towardsdatascience.com/)
#https://medium.com/topic/data-science (https://medium.com/topic/data-science)

#https://www.analyticsvidhya.com/ (https://www.analyticsvidhya.com/)

#StatQuest

#3Blue1Brown

https://www.youtube.com/watch?v=jc2IthslyzM&vl=en (https://www.youtube.com/watch?
v=jc2IthslyzM&vl=en)

Online IDE's for ML & DL


#Google colab

#Kaggle Note Book

Packages
#numpy - Numerical Opearations

#pandas - Handling Dataframes

#matplotlib - Visual Plots

#scikit Learn /sklearn - Machine Learning

#seaborn - Advanced Plots

Python Data Structers


List Tuple Sets Dictionary String

Array Handling Matrix Handling

"""To get a little overview here are a few popular plotting libraries: Matplotlib: low level, provides
lots of freedom Pandas Visualization: easy to use interface, built on Matplotlib Seaborn: high-level
interface, great default styles ggplot: based on R’s ggplot2, uses Grammar of Graphics Plotly: can
create interactive plots"""
In [6]: # defining a variable : In Python there is no need to mention the data type

var1 = 10 # An integer assignment


var2 = 3.146 # A floating point
var3 = 'Python' # A string

print(var1,' ',var2,' ',var3)

10 3.146 Python

In [8]: # Assigning same value to multiple variables

var1 = var2 = var3 = 1


print(var1,' ',var2,' ',var3)

# Assigning Different values to variable in a single expression

var1, var2, var3 = 1, 2.5, "Python"


print(var1,' ',var2,' ',var3)

# Note: commas can be used for multi-assignments

1 1 1
1 2.5 Python

In [13]: # Slicing
# String operations

str = 'Hello World!' # A string

print(str) # Prints complete string


print(str[0]) # Prints first character of the string
print(str[2:5]) # Prints characters starting from 3rd to 5th element
print(str[2:]) # Prints string starting from 3rd character
print(str[:2])
print(str[:])
print(str * 2) # Prints string two times
print(str + "Hello Bvrit") # Prints concatenated string

Hello World!
H
llo
llo World!
He
Hello World!
Hello World!Hello World!
Hello World!Hello Bvrit

In [16]: # reverse string using slicing


n="I Love Python Programming"
n[::-1]

Out[16]: 'gnimmargorP nohtyP evoL I'


In [5]: l1 = [1, 2, 3, 4]
l2 = [5, 6, 7, 8]
l1*3 # Repetion * operator does the job of repetition
l1+l2 # COncatenation

100 in l1
4 in l1

Out[5]: True

In [6]: for i in l1:


print(i)

1
2
3
4

In [7]: for i in l2:


print(i)

5
6
7
8

In [16]: trainees=[]

trainees.append("Pooja")
trainees.append("Mohammed")
trainees.append("Rajani")
trainees[2]="Guru"
trainees.pop()
trainees.reverse()
trainees

Out[16]: ['Mohammed', 'Pooja']

In [19]: # Python Lists

list = ['Lakhsmi', 43, 'Hyderabad', "B.E", "M.TECH", "PhD", 67.5 ] # A list


tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) # A tuple. Tuples are immutable, i

print(list) # Prints complete list


print(list[0]) # Prints first element of the list
print(tuple[1:3]) # Prints elements starting from 2nd till 3rd
print(list[2][4])

['Lakhsmi', 43, 'Hyderabad', 'B.E', 'M.TECH', 'PhD', 67.5]


Lakhsmi
(786, 2.23)
r
In [22]: # Lists are ordered sets of objects, whereas dictionaries are unordered sets. But

#transation = {Purchaseorder:"ZZ12345",Name:"Rajani",Account:"12321423423",Amount
tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127

#print(tel['jack'])
del tel['sape']
print(tel)
tel['irv'] = 4127
print(tel)
print(tel.keys())
print(sorted(tel.keys()))
print(sorted(tel.values()))
print('guido' in tel)
print('jack' not in tel)
print("sape" not in tel)

{'jack': 4098, 'guido': 4127}


{'jack': 4098, 'guido': 4127, 'irv': 4127}
dict_keys(['jack', 'guido', 'irv'])
['guido', 'irv', 'jack']
[4098, 4127, 4127]
True
False
True

In [14]: #Conditioning and looping


for i in range(0,10):

if i%2 == 0:
print("Square of ",i," is :",i*i)

else:
print(i,"is an odd number")
print("loop done")

Square of 0 is : 0
1 is an odd number
Square of 2 is : 4
3 is an odd number
Square of 4 is : 16
5 is an odd number
Square of 6 is : 36
7 is an odd number
Square of 8 is : 64
9 is an odd number
loop done
In [27]: #Built-in Functions¶
print("Sum of array: ",sum([1,2,3,4]))
print("Length of array: ",len([1,2,3,4]))
print("Absolute value: ",abs(-1234))
print("Round value: ",round(1.62234))

import math as m # importing a package


print("Log value: ",m.log(10))

Sum of array: 10
Length of array: 4
Absolute value: 1234
Round value: 2
Log value: 2.302585092994046

In [30]: #Functions

def area(l,w):
a=l*w #Function body
return a

are = area(10,20) #Function Call


b=area(100, 300)
print("Area of rectangle:",are)
print(b)

Area of rectangle: 200


30000

Given below are the ages of students from


Kendriya Vidyalaya. We are building a machine
learning model that uses the age of the
student
as a feature. However, we noimport numpy as np

#arr = [100, 50, 400, 300, 200] arr=[15, 14, 12, 13, 120, 15, 16, 14, 12, 14, 11, 16, 14, 12, 13]
x=np.mean(arr) xtice that our data has certain erroneous values in it. Which of the following
normalization techniques would you use to normalize data with such erroneous values?

[15, 14, 12, 13, 120, 15, 16, 14, 12, 14, 11, 16, 14, 12, 13]

a) z-score b) min-max c) log-transform


In [2]: import numpy=np.std(arr)
yy as np
#arr = [100, 50, 400, 300, 200]
arr=[15, 14, 12, 13, 120, 15, 16, 14, 12, 14, 11, 16, 14, 12, 13]
x=np.mean(arr)
x

Out[2]: 20.733333333333334

In [3]: y=np.std(arr)
y

Out[3]: 26.56932232648942

In [4]: # Z Score
for i in range(len(arr)):
print((arr[i]-x)/y)

-0.21578771422473364
-0.25342510624067555
-0.32869989027255936
-0.29106249825661745
3.7361384474491666
-0.21578771422473364
-0.17815032220879173
-0.25342510624067555
-0.32869989027255936
-0.25342510624067555
-0.36633728228850126
-0.17815032220879173
-0.25342510624067555
-0.32869989027255936
-0.29106249825661745

In [5]: #min-Max
for i in range(len(arr)):
print((arr[i]-min(arr))/(max(arr)-min(arr)))

0.03669724770642202
0.027522935779816515
0.009174311926605505
0.01834862385321101
1.0
0.03669724770642202
0.045871559633027525
0.027522935779816515
0.009174311926605505
0.027522935779816515
0.0
0.045871559633027525
0.027522935779816515
0.009174311926605505
0.01834862385321101
In [7]: import numpy as np
import matplotlib.pyplot as plt

#y = a + bx + cx2
a=10
b=20
c=30
plotx=[]
ploty=[]
for x in range(-100,100):
y=a+b*x+c*x*x
plotx.append(x)
ploty.append(y)

plt.plot(plotx,ploty,"r.")
plt.show()
In [8]: #From the below graphs, select the one that satisfies the equation y=σ(0.1∗x):
import numpy as np
import matplotlib.pyplot as plt

x=[]
y=[]

for i in range(-100,100):
a = 1/(1+np.exp(-0.1*i))
#a = np.std(0.1*i)
x.append(i)
y.append(a)

plt.plot(x, y, 'r--')
plt.show()

Perform z-score normalization and min-max


scaling on the given array and select from the
given options.
arr = [ 100 , 50 , 400 , 300 , 100 ]

In [9]: import numpy as np


arr = [ 100, 50, 400, 300, 100]
x=np.mean(arr)
x

Out[9]: 190.0
In [10]: import numpy as np
arr = [ 100, 50, 400, 300, 100]
y=np.std(arr)
y

Out[10]: 135.64659966250537

In [11]: # Z Score
for i in range(len(arr)):
print((arr[i]-x)/y)

-0.6634888026970371
-1.03209369308428
1.5481405396264198
0.8109307588519342
-0.6634888026970371

In [12]: #min-Max
arr = [ 100, 50, 400, 300, 100]
for i in range(len(arr)):
print((arr[i]-min(arr))/(max(arr)-min(arr)))

0.14285714285714285
0.0
1.0
0.7142857142857143
0.14285714285714285

In [ ]:

In [ ]:

In [ ]:

In [ ]:

You might also like