You are on page 1of 33

Python

Advantage:
1.Easy to Learn
2.Less code
3-4 lines in java

3.Reduce time
4.Interpreter language(line by line)
5.Huge Library
pygame
SQlite
DJango
Numpy
scipy

6.Open source
7.Python is platform Independent

Learn:
1.Bank Application
2.Billing software
3.Ticket Reservation
4.Hotel MS
..............
software:

Download:

https://www.python.org/downloads/windows/

32 bit os -Download Windows x86 executable installer


64-Download Windows x86-64 executable installer

python IDLE:

two modes of software:


1.Shell mode:

Java:
class Anu{
public static void main(String args[]){
Sysytem.put.println("Welcom");
}
}
Python:
print("Welcome")

-get output line by line


-Maths calculations directly

2.Script mode:
-GO to the file menu
-click new file>script mode will open
-type program>go to file > save as
-.py is the extension to save the file

Python Variables:
variable is used as identifier Location

a=10

variable name is a
value = 10

b=10

aneri=5

Basic Data types:


1.Integer:int
it will be having all the numeric numbers
eg:1,2,3,4,5,6,7,90,120,232,244,.........

syntax:
a=20

2.FLoat:float
it will be having all the decimal values
1.2
2.3
4.5
9.0001

syntax:
a=3.111104

3.String:str
collection of character
" "
or
' '
syntax:
a="welcome you all"

or

a='welcome you all'

1.Set index value for String

a="Python course"

a="Welcome to python course"


print(a[12])

2.Find length of a string


a="Aneri"

len(a)=5

a="Welcome to python course"


print(len(a))

3.How to convert all string data type into small letter

a="JiTHU"

lower()

a="Welcome To PYTHON Course"


print(a.lower())

4.How to convert all string data type into capital letter


upper()

a="Welcome to python Course"


print(a.upper())

5.How to replace a string


replace()
a="Welcome to python Course"
print(a.replace("W","H"))

6.How to concadinate a string


a="ANeri"
b="Najila"
c="Jithu"
d=a+" "+b+" "+c
print(d)

7.How to add int & str +

a=20
b="My age is:{}"
print(b.format(a))

a=5
b=4
c="I want{} cup of icecream of {} items"
print(c.format(a,b))

8.How to convert our string first char into Capital letter

a="hello"
capitalize()

a="hello"
print(a.capitalize())
4.Boolean:
true
or
false

keywords in python:
predefined reserved words in python
we can't able to use keywords for defining var,class,function....

if
if-else
False
True
and
or
not
def
class
excpet
elif
None
raise
except
from
import...................................

Python Operators:
it is going to do some operation

1.Aritchmetic oper:
all the mathematical related operations

add +
sub -
mul *
div /
floor div //
modulus -remainder of division %
Exponential-power **

a=4
b=3
print("Exp value is:",a**b)

2.Relation or comparision oper:


we are going to compare ,output will be in boolean formatt.

Equal ==
Not Equal !=
Greater >
Lesser <
Greatr or equal >=
lesser or equal <=
3.Logical oper:Logically and give output in boolean format

Logical AND: and


when both the condition are true---true

t-t=t
t-f=f
f-t=f
f-f=f

a=True
b=True
print(a and b)

a=3
print(a>5 and a<1)

Logical OR:or
when any one is true and one is false----true

t-t=t
t-f=t
f-t=t
f-f=f

a=False
b=True
print(a or b)

Logical NOT:
reverse or oppe

a=True

print(not(a))---false

4.Bitwise oper:

Converting everything in to 0 & 1

bitwise AND:&

1-1=1
1-0=0
0-1=0
0-0=0

a=10
b=24

a=10
b=24
print(a & b)
c=30
d=24
print(c & d)

bitwise OR: |

1-1=1
1-0=1
0-1=1
0-0=0

a=12
b=5

bitwise NOT: ~

aneri=5

print(~aneri)

-6

a=-9
print(~a)

5.Assignment oper:

naj=10

naj +=5 -------15

naj -=7 ---------8

naj *=2 -------16

naj /=4 --------4

anu=10
>>> print(anu)
10
>>> anu +=10
>>> print(anu)
20
>>> anu -=10
>>> print(anu)
10
>>> anu *=3
>>> print(anu)
30
>>> anu /=5
>>> print(anu)
6.0
>>>

6.Membership oper:

in
not in

used to print a data in sequence which is present in a group

aneri=["apple","orange","grapes","banana","cherry"]

print("banana" in aneri)

output-Bool

school=["anu","aneri","najila","jithu","arun"]
print("aneri" in school)

7.Identity oper:
used to check the given data is similar or not

is
is not

a=["apple","Banana"]
b=["Grapes"]

a=["apple","orange"]
a=["apple"]

print(a is not a)

a=["apple","orange"]
a=["orange"]
print(a is a)

Control flow structure:


1.Decision making Statement
---if:
check the condition, if the condition is true---true
false---nothing will be print

a=10
b=20
if a<b:
print("Greater")

username="anupriyan"
password="anu12345"

if username=="anupriyan" and password=="anu12345":


print("Login success")
---if-esle:
if the condition is true---true
else -false----false statement

username="anupriyan"
password="anu12345"

if username=="anupriyan" and password=="anu12345":


print("Login success")
else:
print("Invalid credintial")

username=input("Enter a Username:")
password=input("Enter a password:")

if username=="anupriyan" and password=="anu12345":


print("Login success")
else:
print("Invalid credintial")

---elif:short form of else if


to check the multiple condition

username=input("Enter a Username:")
password=input("Enter a password:")

if username=="anupriyan" and password=="anu12345":


print("Login success")

elif username=="anu" or password=="anu12345":


print("Invalid username")

elif username=="anupriyan" or password=="anu123":


print("Invalid password")

else:
print("Invalid credintial")

----nested if:
within a if statement onemore if statement

a=20
if a>10:
print("a is greater")
if a >25:
print("15 is greater")
else:
print("number is lesser")

a=150
if a<100:
print("lesser")
if a==75:
print("equal")
else:
print("greater")

2.Looping Statement:Repetation

---for loop:
it is an iterator used to print a data in sequqnce order

a=["apple","orange","grapes","cherry"]
for fruits in a:
print(fruits)

for a in range(1,10):
print(a)

---while loop:

it is also like a iterator


used to print the data by checking the condition

a=1
while a<10:
print(a)
a+=2

--break in for:
a=[1,2,3,4,5,6]
a=4
break

for i in range(20):
if i==12:
break

print(i)

for a in "Aneri patel":


if a=="e":
break
print(a)

--continue:
for a in "Aneri patel":
if a=="p":
continue
print(a)

for a in range(10):
if a==5:
continue
print(a)

while loop break:

a=1
while a<20:
print(a)
if a==5:
break
a+=1

a=1
while a<20:
a+=1
if a==5:
continue
print(a)

--pass:
for a in [1,2,3,4,5]:
if a==3:
pass
print("this is pass block")
print(a)

function in python:
-perform some task
--break the modules into groups
--code reuse

syntax:

def show(arg):
.......................
function call:
def anu():
print("Hello Everyone")

anu()

function arg:

def anu(name):
print("my name is:"+name)
anu("shaji")
anu("aneri")

def add(a,b):
c=a+b
print("added value is:",c)
add(4,5)

def sub(a,b,c):
d=a-b-c
print("Sub value is:",d)
sub(9,3,2)

def anu():
a=5
print("inside value is:",a)

a=10
anu()
print("outside valus is :",a)

Types of arguments:
1.Keyword argument:

syntax:
def demo(arg):
.....................print............
demo(values)

def anu(name="Najila", msg="Welcome you"):


print("Hello", name, msg)
anu("Anu","How are you")

2.Default argument:
def anu(name, msg="Welcome you"):
print("Hello", name, msg)
anu("")

3.Arbitary arguments:

more number of arg value we can add

def demo(*fruits):
for a in fruits:
print("i like:", a)

demo("apple","orange","grapes","banana")

recursion function:when a function call itself many times

factorial:
def demo(a):
if a==1:
return 1
else:
return(a *demo(a-1))
num=int(input("Enter a number:"))
print("the factorial is:",demo(num))

Fibonnocie series:

Lambda Function:
it will have many arguments but only one expression

---function objects are required

syntax:

lambda arg:expression

anu=lambda a:a+5
print(anu(5))

filter:

demo=[1,6,8,5,11,12,4,3,16,18,21,22]
ans=list(filter(lambda a:(a%2!=0),demo))
print(ans)

String literal:
anna---anna
bb--bb
malayalam--

demo=["aneri","anna","bb","malayalam","jithu","najila"]
ans=list(filter(lambda a:(a=="".join(reversed(a))),demo))
print(ans)

anagrams---common chaar

aneri
einra

from collections import Counter


anu=["aneri","jithu","najila","anup"]
str="einra"
ans=list(filter(lambda a:(Counter(str)==Counter(a)),anu))
print(ans)

map in lambda:
a=[2,4,6]
b=[3,5,7]
ans=map(lambda x,y:x+y,a,b)
print(list(ans))

Data structure:
data-collection of information
structure- correct view

collection of information in a structured format

4 types of data structure:

1.List: it is a data structure


used to store the data in list format

syntax:

a=[ 1,2,3,4]

properties:
1.mutable behaviour:update, add, delete.......
len
index

add single value into list -append


multiple value- extend

count - count the value


slice:print(a[:6])

remove:which data we want to remove


pop:remove the value LIFO
copy: copy the data

a=[1,2,3,4,5,6,7,8,9,10]
a.clear()

print(a)

a=["Jithu","aneri","najila"]

a[2]="anu"
print(a)

2.Tuple: it is also one of the data structure:


store the data
properties:
immutable behaviour:unchangable

syntax:

a=( 1,2,3,4,5)
a=("anu")

len
count
index
slice

3.Set
store the data in unorder way

syntax:

a={ 1,2,3,4,5,6,7}

set operations:
1.set union:

a={1,2,3,4,5}
b={4,5,6,7}
a.union(b)

2.set intersection:

a={1,2,3,4,5,6,7,8,9}
b={5,6,7,8,9,10,11,12}
print(a.intersection(b))

3.set difference:
a={1,2,3,4,5,6,7,8,9}
b={5,6,7,8,9,10,11,12}
print(a.difference(b))

4.symmetric difference:
a={1,2,3,4,5,6,7,8,9}
b={5,6,7,8,9,10,11,12}
print(a.symmetric_difference(b))

mutable behaviour:sset is mutable behaviour


-add,update,delete.....

a={1,2,3,4,5,6,7,8,9}
print(len(a))

a={1,2,3,4,5,6,7,8,9}
a.add(10)
print(a)
a={1,2,3,4,5,6,7,8,9}
a.update([10,11,13,12])
print(a)

a={1,2,3,4,5,6,7,8,9}
a.remove(5)
print(a)

a={1,2,3,4,5,6,7,8,9}
a.pop()
print(a)

a={1,2,3,4,5,6,7,8,9}
a.discard(9)
print(a)

4.Dictionary:
unorder collection of data

--key and value pair


name:jithu
address:India

syntax:
a={1:"anu", 2:"najila", 3:"aneri"}

a={1:"anu", 2:"aneri"}
a.pop(1)
print(a)

a={1:"anu", 2:"aneri"}
a.clear()
print(a)

Stack:works on the prin of Last in first out LIFO

add,pop

Queue:works on the prin of First in First out

Modules & Package in python:

modules:
file .py ....modules

import aneri
aneri.function()

pre defined modules - lot of modules


own module - .py

import modulename
print

>>> import datetime


>>> a=datetime.datetime.now()
>>> print(a)
2020-08-28 17:58:16.794214
>>> print(a.year)
2020
>>> print(a.day)
28
>>> print(a.hour)
17
>>> print(a.minute)
58
>>>

GUI - Graphical user interface window - tkinter


2 - line

Packages:
collection of module is called package

1.Basic example
eg:Games

2.Real time example


eg:Games

File system:
we are going to do the file Handling

open
read - r

a=open("D:/open.txt","r")
print(a.readline())
print(a.readline())
print(a.readline())

write: overwrite a file-w


a=open("D:/open.txt","w")
a.write("Hi najila,jithu,aneri How r u all")
a.close()

create a new file: x


a=open("D:/anu.pptx","x")
delete:
import os
os.remove("D:/jithuu.txt")

append: a

a=open("D:/open.txt","a")
a.write(" I hope you are fine and guod. welcome you all")
a.close()

Error and Exceptional Handling:

Errros:
Syntax error
attribute error
value
type error
index error
indent error
name error
zero div error
raise runtime error
assertion error.........

Exception handling: handle the errror

try-
program if we write inside the try block
-check whether the prg a any error not

assertion-check whether the prg as any error or not

except-handle a error
except nameerror---
except Typeerror---

throw-throw a error manually

finally-printing in finally----print output

Example 1:

try:
a=int(input("Enter a 1st number:"))
b=int(input("Enter a 2nd number:"))
c=a/b
print(c)
except ZeroDivisionError:
print("can't div by zero")
Example 2:
try:
a=int(input("Enter a 1st number:"))
b=int(input("Enter a 2nd number:"))
c=a/b
print(c)
except ZeroDivisionError:
print("can't div by zero")
except ValueError:
print("enter number alone")
finally:
print("bye......")

Example 3:

try:
f=open("D:/oooopen.txt","r")
print(f.read())
except IOError:
print("file not found")
else:
print("file is opened successfullyy")
f.close()

Example 4:
try:
a=int(input("Enter a age:"))
if(a<18):
raise ValueError
else:
print("you have rights to vote")
except ValueError:
print("not eligible to vote")

Example 5:

try:
a=int(input("Enter a age:"))
if(a<=0):
raise ValueError
else:
print("correct ")
except ValueError:
print("enter +ve number")

Oops in python:
object oriented programming language

Adv:
1. reuse
2.Easy to create any app
3.secure

-class
-object
-inheritance
-polymorphism
-Abstraction
-Encapsulation

1.Class:
it is like a blueprint, class as attributes and behaivours

Human----class
attr-name.,age,gender,height,weight,addres,........
behiv-run,sing,dance,walk,eat......................

syntax:
class Aneri
......................
....................

2.Object:
-object is an instance of class
-obj as entity that have state and behaviour

syntax:

obj=classname()

Ex 1:

class Human:
def eat(self):
print("Eating")

anu=Human()
anu.eat()

Ex 2:
class Emp:
def __init__(self,name,address):
self.name=name;
self.address=address;
def show(self):
print(self.name,self.address)
najila=Emp("Aneri","India")
najila.show()

3.Inheritance:

one class to another class

class A:
........eat........

class B(A):
......run........

obj=B()
obj..
run
eat

1.Single Inheritance:inherit from single base class

class Aneri:
def eat(self):
print("eating..")

class Jithu(Aneri):
def run(self):
print("running")

obj=Jithu()
obj.eat()
obj.run()

2.Multiple Inheritance:inherit from 2 or more than base class

class A
....eat.....

class B
.......run.....

class C(A,B)
.........sleep......
obj=C()

class Aneri:
def eat(self):
print("eating..")

class Jithu:
def run(self):
print("running")

class Najila(Aneri,Jithu):
def sleep(self):
print("sleeping")

obj=Najila()
obj.eat()
obj.run()
obj.sleep()

3.Multilevel Inheritance:
inherit using level by level

class A:
...eat.....----------------eat
class B(A):
....sleep....-----------eat,sleep

class C(B):
........run....--------------eat,sleep,run

class D(C):
.........jump......------eat,sleep,run,jump

obj=D()

class Aneri:
def eat(self):
print("eating..")

class Jithu(Aneri):
def run(self):
print("running")

class Najila(Jithu):
def sleep(self):
print("sleeping")

class Anu(Najila):
def lazy(self):
print("Lazy")

obj=Anu()
obj.eat()
obj.run()
obj.sleep()
obj.lazy()

4.Hybrid inheritance:
similar to multiple inheritance

polymorphism:
poly-many
perform many task

def add(a,b)

def add(a,b,c)

add(3,4,3)

class Najila:
def eat(self):
print("najila eating")

class Jithu:
def eat(self):
print("jithu eating")

obj=Najila()
obj.eat()

operator overloading:
same operator perform many task

print(4 * "aneri")

function overriding:
class Aneri():
def eat(self):
print("Aneri eating")

class Jithu(Aneri):
def eat(self):
Aneri.eat(self)
print("jithu eating")

obj=Jithu()
obj.eat()

Abstraction:
import abstract class

from abc import ABC,abstractmethod


class Najila(ABC):
def eat(self):
pass

class Aneri(Najila):
def eat(self):
print("aneri eating")

class Jithu(Najila):
def eat(self):
print("jithu eating")

obj=Aneri()
obj.eat()

obj=Jithu()
obj.eat()

Encapsulation:
prevent from direct modification
class Computer:
def __init__(self):
self.__maxprice=900

def sell(self):
print(format(self.__maxprice))
def setMaxPrice(self,price):
self.__maxprice=price

a=Computer()
a.sell()

#change price
a.__maxprice=2000
a.sell()

a.setMaxPrice(2000)
a.sell()

constructor:

class Human:
def __init__(self,name,address,professional):
self.name=name
self.address=address
self.professional=professional

def result(self):
print(self.name,self.address,self.professional)

obj=Human("Aneri","India","Developer")
obj.result()

GUI: Graphical User Interface

tkinter - module

widget:
button
heading label
entry
radio
check
title of our tkinter
add DB
message box
listbox
spinbox
........

1.Create tkinter window


from tkinter import *
anu=Tk()
2.Button in tkinter window

from tkinter import *


anu=Tk()

a=Button(anu, text="Najila",height=2, width=20,bg="white", fg="red",


font=("bold",20))
a.pack(side=LEFT)

b=Button(anu, text="Jithu", height=2, width=20, bg="yellow", fg="green",


font=("bold",20))
b.pack(side=RIGHT)

c=Button(anu, text="Aneri", height=2, width=20, bg="blue", fg="red",


font=("bold",20))
c.pack(side=TOP)

d=Button(anu, text="Anu", height=2, width=20, bg="pink", fg="blue",


font=("bold",20))
d.pack(side=BOTTOM)

anu.mainloop()

3.Check Button:

from tkinter import *


from tkinter import messagebox
anu=Tk()

def python():
messagebox.showinfo("Python","yes you are attending python")
def java():
messagebox.showinfo("Java","No you are not into java")

lb=Label(anu,text="Which course you are into?",font=("bold",20))


lb.pack()

a=Checkbutton(anu, text="Java", font=("bold",20), command=java)


a.pack()

b=Checkbutton(anu, text="Python", font=("bold",20), command=python)


b.pack()

anu.mainloop()

4.Label: Heading, Paragraph, title...

from tkinter import *


from tkinter import messagebox
anu=Tk()

def python():
messagebox.showinfo("Python","yes you are attending python")
def java():
messagebox.showinfo("Java","No you are not into java")

lb=Label(anu,text="Which course you are into?",font=("bold",20))


lb.pack()

a=Radiobutton(anu, text="Java", font=("bold",20), command=java)


a.pack()

b=Radiobutton(anu, text="Python", font=("bold",20), command=python)


b.pack()

anu.title("Online exam")
anu.mainloop()

5.form - REg, login, contac.....

Label
ENtry

size on tkinter window: geometry

firstname
lastname
email
gender
mobile
password

button

from tkinter import *

anu=Tk()

def task():
print("FirstName:", e1.get())
print("LastName:",e2.get())
print("Gender:", var.get())
print("Email:", e3.get())
print("Mobile no:", e4.get())
print("Password:",e5.get())

a=Label(anu, text="Registration form",font=("bold",20), fg="blue")


a.place(x=150,y=100)

b=Label(anu, text="FirstName", font=("bold", 10))


b.place(x=160, y=150)

e1=Entry(anu)
e1.place(x=250, y=150)

c=Label(anu, text="LastName", font=("bold",10))


c.place(x=160, y=180)

e2=Entry(anu)
e2.place(x=250, y=180)
d=Label(anu, text="Gender", font=("bold",10))
d.place(x=160, y=210)

var=IntVar()
Radiobutton(anu, text="male",variable=var, value=0).place(x=250, y=210)
Radiobutton(anu, text="Female",variable=var,value=1).place(x=300, y=210)

f=Label(anu, text="Email", font=("bold",10))


f.place(x=160, y=240)

e3=Entry(anu)
e3.place(x=250, y=240)

g=Label(anu, text="Mobile no", font=("bold",10))


g.place(x=160, y=270)

e4=Entry(anu)
e4.place(x=250, y=270)

h=Label(anu, text="Password", font=("bold",10))


h.place(x=160, y=300)

e5=Entry(anu,show='*')
e5.place(x=250, y=300)

Button(anu, text="Signup",bg="red", fg="yellow", font=("bold",10),


command=task).place(x=270, y=340)
anu.configure(bg="pink")
anu.geometry("500x500")
anu.title("Registration form")
anu.mainloop()

listbox in tkinter:

from tkinter import *

anu=Tk()

a=Label(anu, text="Python course")

b=Listbox(anu)
b.insert(1,"Jithu")
b.insert(2,"Najila")
b.insert(3,"Aneri")
b.insert(4,"ANupriyan")
b.insert(5,"shaji")
btn=Button(anu,text="Delete",command=lambda b=b:b.delete(ANCHOR))
a.pack()
b.pack()
btn.pack()
anu.geometry("300x300")
anu.mainloop()

spinbox:
from tkinter import *

anu=Tk()
a=Spinbox(anu, from_=0, to=100)
a.pack()
anu.geometry("300x300")
anu.mainloop()

combobox:

from tkinter import *


from tkinter import ttk
anu=Tk()
ttk.Label(anu, text="Select a month:",font=("arail", 10)).grid(column=0, row=15,
padx=10, pady=25)
a=StringVar()
month=ttk.Combobox(anu, width=30,textvariable=a)
month['values']=('January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December')
month.grid(column=1, row=15)
month.current(2)

anu.geometry("600x600")
anu.mainloop()

Frame:
from tkinter import *

anu=Tk()
f1=LabelFrame(anu, text="Aneri patel")
f1.pack(fill="both", expand="yes")

a=Label(f1, text="This frame belongs to Aneri patel")


a.pack()

f2=LabelFrame(anu,text="Jithu shaji")
f2.pack(fill="both",expand="yes")

b=Label(f2, text="Thi sframe belongs to Jithu")


b.pack()
anu.geometry("600x600")
anu.mainloop()

messagebox:

showinfo:
from tkinter import *
from tkinter import messagebox
anu=Tk()
messagebox.showinfo("Information","Software installed successfully")
anu.mainloop()
show warning:
from tkinter import *
from tkinter import messagebox
anu=Tk()
messagebox.showwarning("Warning","Disk full, delete some data")
anu.mainloop()

show error:
from tkinter import *
from tkinter import messagebox
anu=Tk()
messagebox.showerror("Error","Virus in the file")
anu.mainloop()

ask question:
from tkinter import *
from tkinter import messagebox
anu=Tk()
messagebox.askquestion("Confirm","Are you sure?")
anu.mainloop()

Multi threading: many task or process


able to perform a multiple thread at the same time

eg: task manager

methods:
start() - start a new thread
run() - call start methos to run the app
isalive() - to check whether the thread is still running or not
setname() - set a name of thread
getname() - get a thread name
join() - terminate a thread

import threading
import time

exitFlag = 0

class myThread (threading.Thread):


def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
print ("Starting " + self.name)
print_time(self.name, 5, self.counter)
print ("Exiting " + self.name)

def print_time(threadName, counter, delay):


while counter:
if exitFlag:
threadName.exit()
time.sleep(delay)
print ("%s: %s" % (threadName, time.ctime(time.time())))
counter -= 1

# Create new threads


thread1 = myThread(1, "Google", 1)
thread2 = myThread(2, "What's app", 2)
thread3 = myThread(3, "Facebook", 3)
thread4 = myThread(4,"Instagram",4)
thread5 = myThread(5,"twitter",5)

# Start new Threads


thread1.start()
thread1.join()
thread2.start()
thread2.join()
thread3.start()
thread3.join()
thread4.start()
thread4.join()
thread5.start()
thread5.join()
print ("Exiting Main Thread")

Synchronization of multi threading:


3 methods:

1.lock.acq()
2.block()
3.release.acq()

Networking in python:

network: connection

networking: communication( client and server)

socket : module, used to communicate

--end point of two way communication

client socket method:


1.connect

server socket method:


1.bind
2.listen
3.accept
comman method:
send
recv

DataBase Connectivity:

School:
----student,staff,lib
Insert query -
select - fetch
update-
delete-

sql
mysql
mongo db - nosql
oracle
sqlite3

mysql/sql

software:
python IDLE---editor--1
mysql--DB----2

Jithu:Linux
https://dev.mysql.com/downloads/mysql/

Najila:windows 32
https://dev.mysql.com/downloads/windows/installer/8.0.html

pymysql--python to connect mysql---3

Afterdownloading:

Steps:
1.open the mysql folder
2.open the bin folder > copy bin path
3.open cmd>run as admin
4.cd C:\Users\Livewire\Desktop\mysql-5.7.24-winx64\mysql-5.7.24-winx64\bin
5.>>mysqld --console --initialize

A temporary password is generated for root@localhost: Z,jhTF+%p10D

Localhost:127.0.0.1
user:root
password: :OrWw_Ex:4ki

6. start DB server
>mysqld --console

7.Open one more cmd prompt as admin


>>cd C:\Users\Livewire\Desktop\mysql-5.7.24-winx64\mysql-5.7.24-winx64\bin

8.initialize
>>mysqld -initialize

9.connect with DB server

>>mysql -u root -p

C:\Users\Livewire\Desktop\mysql-5.7.24-winx64\mysql-5.7.24-winx64\bin>mysql -u root
-p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

10. change the password:


>>alter user "root"@"localhost" identified by "najila";
query ok

11. cltr+z
come out and connect once again

12. connect with DB again

13.create DB name
>create database college;

14.mysql> use college;


Database changed

15.
open pymysql >>>pymysql folder will be there>>>>copy the folder

>>C:\Users\Livewire\AppData\Local\Programs\Python\Python37\Lib

paste it here

16. create a Table inside my Database: college

import pymysql

db = pymysql.connect("localhost","root","najila","college")

cursor = db.cursor()

cursor.execute("DROP TABLE IF EXISTS student")

sql = """CREATE TABLE student (


name CHAR(40) ,
address CHAR(30),
mark INT(10),
rank INT(10) )"""

cursor.execute(sql)
print("Student Table Created")

db.close()
17. Insert value into table:

import pymysql

db = pymysql.connect("localhost","root","najila","college" )

cursor = db.cursor()

sql = """INSERT INTO student(name,


address,mark, rank)
VALUES ('Najila', 'Kerala',94, 3)"""
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()

print("value is Inserted")
db.close()
eng5.ts@livewireindia.com

+91 9444807306(Whats)

You might also like