PYTHON CLASSES
C++ isn’t platform independent.
Python is cruise platform
C- compiler
Python- interpreter
[Link] IS PYTHON?
• Python is an object oriented programming and high level
language, interpreted, dynamic, and multipurpose
programming language.
• Compiler translates at a single time.
• Interpreter translates line by line. Translator to convert our
source code into binary code.
❖ PYTHON EXECUTION:
(How to execute python program in your pc?)
• [Link] (install)
[Link] VARIABLES
Variables are nothing it’s just a name in a memory area. Once a
variable is defined that means a memory is allocated in a RAM.
❖ SOME RULES TO ASSIGN VARIABLES IN PYTHON:
• The name of the variable can be combination of lower case letter
(a to z), uppercase letters (A to Z), digits (0 to 9), and
underscore (_) characters.
• The variable name must start with a letter.
• A special character (!, ?, %, etc.) isn’t allowed while naming a
variable.
• Variable are case sensitive (a != A).
• Value can be assigned to a variable using equal
operator.
❖ HOW TO ASSIGN VARIABLE IN PYTHON:
• Assign separate value with separate variable. {x1=100
x2=100.25 x3="welcome" print (x1 + " " + x2 + " " +x3}
• Assign multiple variables for simple value. {x1=x2=x3 print
(x1)}
• Assign multiple variables for a multiple values in a single line.
[Link] OPERATORS
Operator is nothing but a symbol that is used to produce an output.
In python we use seven types of operators.
1. Arithmetic operator
Addition, Subtraction, Multiplication, Division...
x = 100
y = 300
z = x + y
print (z)
400
z = x * y
print (z)
30000
z = x - y
print (z)
-200
z = x/y
print (z)
0.333333333333333
z = x//y
print (z)
0
z = x%y
print (z)
100
z = 10 ** 2
print (z)
100
2. Relational operator -
Equal not equal.
x = 100
y = 500
x == y
False
x != y
True
x > y
False
x < y
True
3. Assignment operator
Equal assignment {+=}
a = 100
a += 50
print (a)
150
a -= 50
print (a)
50
a //= 50
a
100
a/=50
a
2.0
a %= 50
a
2.0
4. Logical operator
“and”, “or”, “not”
and- incase of this operator if all statements are true then output will be ‘true’ otherwise ‘false’.
Ex --> a = 50
b = 60
c = 70
a > b and b > c and c > a
False
or- incase of this operator if anyone statement is true from rest of them then output will be true
otherwise false
a > b or b > c or c > a
True
not- in case of this operator if the input is true then output will be false otherwise vice versa.
not (a > b or b > c or c > a)
False
5. Identity operator
“is” and “is not” {work on behalf of ids of the variable}
is {==} TYPE OF !!!
is not {!=}
Ex-> a = 100
b = 200
a is b
False
a is not b
True
6. Membership operator
“ in “ and “not in “
Ex-> data = [1,2,3]
user = 5
user in data
false
user not in data
True
“a” in “aakar”
True
“A” in “anushka”
False
7. Bitwise Operators
[Link] USER INPUTS
#FOR STRING
input ()
#FOR INTEGER
int (input () )
#FOR FLOATING/DECIMAL VALUE
float ( input () )
❖ Condition 1
Print (“Please enter your name“)
n = input ()
print (“enter your age”)
a= int (input () )
print (“hi”, n, “your age is “, a )
❖ Condition 2
Print (“Please enter your name “, end=“”)
n = input ()
Print (“Please enter your age “, end=“”)
a= int ( input () )
Print (“hi”, n, “your age is”, a, end=“”)
❖ Condition 3
n = input (“enter your name: “)
a = int (input (“enter your age”))
print (f” Hi {n}, your age is {a}.”)
❖ Condition 4
n = input (“enter your name: \n“)
a = int (input (“enter your age \n”))
print (f”hi {n}, your age is {a}.”)
{III rd. class}
[Link] CONDITIONAL
STATEMENTS:
❖ Python if condition:
Whenever you want to execute single block statement then v use this
condition.
Ex-> print (“Please enter Id and Password: ”)
i = (“Id: “)
p = input (“Password”)
if (i == “python” and p==“py@123”) :
print (“Welcome to Python programming language “)
print (“Thanks for coming. Bye!”)
❖ Python if else condition:
Whenever you want to execute 2 block statements (if and else), then
v use the concept of if else condition.
Ex-> print (“Please enter Id and Password: ”)
i = (“Id: “)
p = input (“Password”)
if (i == “python” and p==“py@123”) :
print (“Welcome to Python programming language “)
else:
print (“Sorry, invalid user Id and Password.”)
print (“Thanks for coming. Bye!”)
❖ Python elif condition:
To execute multiple block statements use python elif statement.
Ex-> a = 100
if (a > 50): | OUTPUT:
print (“My name is Anushka. ”) |My name is Anushka.
elif (a>60):
print (“My name is Vitthal. ”)
elif (a>70):
print(“My name is Aakar. ”)
else:
print(“Invalid input. ”),
❖ Python Nested if else condition:
To execute one if-else condition inside another in python.
While loop
attempts = 3
while True:
m = int (input(“Maths:” ))
If (m < 1 or m > 100):
print (invalid marks. Please enter valid marks. “)
if (attempts == 0 ):
time
else:
break
[Link] LOOPING CONCEPTS
In python, we use 2 types of loops:
❖ WHILE LOOP
Ex->
i = 1
while (i <= 100):
print i
i = 100
while (i >= 1):
print (i, end=" ")
i -= 1
❖ FOR LOOP
Ex->
for i in range (1,100):
print (i, end=" ")
for i in range(100, 0, -1):
print(i, end=" ")
[Link] PROJECTS
❖ PROGRAM TO CHECK WHETHER A NUMBER IS EVEN OR
ODD:
import time
print ("Welcome to Odd/Even identi er! ")
n = int (input ("Enter the number you want to classify into odd or even: "))
if (n%2 == 0):
print (n, " is an even number. ")
else:
print (n, " is an odd number. ")
❖ PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR
NOT:
a = int (input("Enter a number to check if it is prime or not: "))
b = 0
for i in range (2, a+1):
if (n % i == 0):
b += 1
if (b == 1):
print (a, "is a prime number. ")
else:
print (a, "is not a prime number. ")
NESTED FOR LOOP:
Ex->
for i in range (1, 6):
print (" ")
for j in range (1, 6):
print ( j, end=" ")
TABLES
for i in range (1, 20):
print ("")
for j in range (1, 20):
fi
print (i * j, end=" ")
c = 1
for i in range (1, 6):
print ()
for j in range (1, 6):
print (c, end=" ")
c += 1
❖ PROGRAM TO PRINT TABLES TILL A GIVEN RANGE:
n = int(input("Please enter the no for which you want to print the table: "))
for u in range (1, n+1):
print (" ")
for v in range (1, 11):
print (f" {u} * {v} = ", u * v)
❖ PROGRAM TO PRINT PRIME NO.S TILL A GIVEN RANGE:
nal = int(input(“Enter the nal range no: “))
for i in range(2, nal+1):
if i > 1:
for j in range(2, i):
if (i % j) == 0:
break
else:
print(i)
❖ PROGRAM TO PRINT PRIME NO.S IN BETWEEN INITIAL &
FINAL RANGE:
initial = int(input("Enter initial range: "))
nal = int(input("Enter nal range: "))
for i in range(initial, nal + 1):
if i > 1:
for j in range(2, i):
if (i % j) == 0:
break
else:
fi
fi
fi
fi
fi
fi
print(i)
[Link] COMMANDS TO SHUT DOWN PC:
input os
———(content)————
[Link](“Shutdown
-f”)
I. PYTHON PATTERS:
❖ PROGRAM TO PRINT 2 RIGHT-ANGLED TRIANGLES:
for i in range (1, 6):
for j in range (1, i+1):
print ("*", end="")
print ()
for i in range (5, 0, -1):
for j in range (1, i+1):
print ("*", end="")
print ()
Homework
❖ PROGRAM TO PRINT EQUILATERAL TRIANGLES THRU BOTH
WAYS:
for i in range (9):
for j in range (8-i):
print (end=" ")
for j in range (i+1):
print (" *", end=" ")
print()
for i in range (9, 0, -1):
for j in range (9-i):
print (end=" ")
for j in range (i):
print (" *", end=" ")
print()
[Link] CONTROL STATEMENT:
In python, we use 3 types of control statements:
❖ PASS
ac = int(input("Enter your acc no: "))
if (ac == 12345):
print ("Hi Vitthal! ")
elif (ac == 23456):
pass
elif (ac == 34567):
print ("Hi Anushka! ")
elif (ac == 45678):
pass
elif (ac == 56789):
print ("Hi Aakar! ")
else:
print ("Account no. entered is invalid. ")
❖ BREAK
for i in range (1, 101):
if (i % 5 == 0):
break
print (i)
❖ CONTINUE
for i in range (1, 101):
if (i % 5 == 0):
continue
print (i)
[Link] DATA TYPE CASTING:
The conversion of one data type into another data type into
another data type is called data type casting.
int – to convert into integer
float – to convert into float
str – to convert into string
[Link] OCTAGONAL, BINARY AND
HEXAGONAL NO.S:
bin(100)
'0b1100100'
>>> oct(100)
'0o144'
[Link] MODULES:
In python we use 6 types of data types:
a) Number {functions in different modules acc to
requirement}: Python no data type is used to store numeric
value. They are immutable data types, i.e. changing the value of
a no. Data type no result in a new allocated object.
#3 types:
1. Mathematical (55)
Abs(x):
abs(-128)
128
▪ Returns the absolute value of x
▪ Return type-> integer
▪ Outside maths module
fabs(x):
[Link](234)
234.0
▪ Returns the absolute value of x
▪ Float
▪ Inside maths module
ceil(x):
[Link](100.01)
101
▪ Inside maths module
▪ Returns the ceiling (increasing) value of x
floor(x):
[Link](-14.99)
-15
▪ Returns the flooring (decreasing) value of x.
log(x):
[Link](
▪ The log function returns the logarithmic value of x.
exp(x):
[Link](10)
22026.465794806718
▪ It returns the exponential value of x.
max:
▪ Outside maths module.
▪ Returns the maximum value out of given integer/float values.
min(x):
▪ Opposite to max function.
2. Random
choice(x):
▪ gives a random value
o [Link]("Anu")
'n'
o [Link](range(1, 101))
4
o data = [1, 2, 3, 4, 5, 6]
[Link](data)
4
shuffle(x):
▪ shuffles data
o [Link](data)
data
[8, 9, 3, 1, 7, 5, 4, 10, 6, 2]
random(x):
▪ No argument required
▪ Range between 0 nd 1.
▪ Max 15 – 16 digits.
o int (round ([Link](), 2) * 100)
b) String: Python string is the simplest and easy to use. The
advantage of using this is that it can be accessed from both
the directions (forwards as well as backwards.
➢ Forward indexing starts from 0, 1, 2....
➢ Backward indexing starts from -1, -2, -3….
❖ CHECKING IF SOMETHING IS PALINDROME OR NOT:
o st = input("Enter your string: ")
l = len (st)
c = 0
for i in range (l-1, -1, -1):
print (st[c], "\t", st[i])
c += 1
c) List: Python list is a mutable (change, delete or insert) data
type.
❖ HOW TO CREATE A LIST?
In Python we can create lists using sq brackets [].
❖ TYPES OF LISTS:
BLANK LISTS:
x1 = []
LIST HAVING SIMILAR DATA TYPE:
X2 = 100, 200
LIST HAVING NO SIMILAR DATA TYPE:
X3 = “WELCOME”, “2293”
NESTED LIST:
❖ HOW TO ACCESS ELEMENTS FROM A LIST:
x = [9, 2, 3, 1, 5, 4, 3, 9, 2, 6, 5, 6, 7, 8, 8]
search = int(input("Please enter the number you want to search: "))
c = 0
for i in x:
if (i == search):
c += 1
print ("Total number of", search, "is", c)
❖ HOW TO CHANGE ELEMENTS IN A LIST:
>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x [ 0 ] = 100
>>> x
[100, 2, 3, 4, 5, 6, 7, 8, 9]
a = [1,2,3,4,5,2,4,3,2,5,2,2,4,5,3]
l = len(a)
print ("The current list is: ", a)
user = int (input ("Please enter the no you wish to change: "))
new = int (input ("Please enter the no into which you wish to change
the previous entered no: "))
for i in range (l):
if ( a[i] == user ):
a[i] = new
print("The New list is: ", a)
❖ HOW TO ADD/INSERT ELEMENTS IN A LIST:
We use two methods to insert or add elements in a list:
o Append Adds elements in the last.
>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [Link](100)
>>> x
[1, 2, 3, 4, 5, 6, 7, 8, 9, 100]
o Insert Can be added anywhere we want
>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [Link](0,1000)
>>> x
[1000, 1, 2, 3, 4, 5, 6, 7, 8, 9]
u_id and u_pwd
loop = 10 times
I loop = pls enter id and pwd
10 times id and pwd
id into a blank list
pwd into pwd list
print id and pwd
u_id = [ ]
u_pw = [ ]
for i in range (1, 3):
x = (int(input("Enter your id: ")))
u_id.append(x)
y = (int(input("Enter your password: ")))
u_pw.append(y)
print ("Your IDs are: ", u_id)
print ("Your passwords are: ", u_pw)
❖HOW TO DELETE ELEMENTS IN A LIST:
We use four methods to delete elements from a list:
o Del keyword Deletes index number.
>>> x = [1,2,3,4,5,6,7,8,9]
>>> del x[3]
>>> x
[1, 2, 3, 5, 6, 7, 8, 9]
o pop method If no argument passed then it deletes the last
index by default. It shows the number that is gonna be
deleted. Deletes using index number as argument.
>>> x = [1,2,3,4,5,6,7,8,9]
>>> [Link]()
9
>>> x
[1, 2, 3, 4, 5, 6, 7, 8]
>>> [Link](2)
3
>>> x
[1, 2, 4, 5, 6, 7, 8, 9]
o remove method Deletes using object as argument.
>>> x = [1,2,3,4,5,6,7,8,9]
>>> [Link](4)
>>> x
[1, 2, 3, 5, 6, 7, 8, 9]
o clear method Never deletes the whole list but makes it a
blank list.
>>> y = [1,2,3,4,5,6,7,8,9,9,9,9]
>>> [Link]()
>>> y
[]
Me Description
tho
app Adds an element at the end of the list
end
cop Returns a copy of the list
y()
cou Returns the number of elements with the specified value
nt()
ext Add the elements of a list (or any iterable), to the end
end of the current list
ind Returns the index of the first element with the specified
ex( value
ins Adds an element at the specified position
ert(
rev Reverses the order of the list
ers
sort Sorts the list
()
x = [4,6,7,8,4,2,4,5,6,7,4]
print ("Elements before deleted: ", x)
u = int(input("Please enter the no. you want to delete:
"))
for i in x:
if ( i == u ):
[Link](i)
print ("Elements after deleted: ", x)
❖ INBUILT FUNCTIONS OF PYTHON LIST:
d) Tuple: Python tuple is an immutable data type and it is
similar to lists. Only one difference is that tuple is
inclosed between paranthesis. Tuple is faster than lists.
❖ HOW TO CREATE A TUPLE:
BLANK TUPLE:
x1 = []
TUPLE HAVING SIMILAR DATA TYPE:
X2 = [100, 200]
TUPLE HAVING NO SIMILAR DATA TYPE:
X3 = [“WELCOME”, “2293”]
NESTED TUPLE:
x = tuple(x) TO CHANGE INTO TUPLE
x = list(x) TO CHANGE INTO LIST
e) Dictionary: Dictionary is a mutable data type. With the help
of {} curly brackets we can create a dictionary and separate it
by (;) colon. It consists of three components:
o Keys : [Link]() finds the keys in a dict
o Values: [Link] () finds the values in a dict
o Items: [Link]() finds the items in a dict
{keys: value } ITEMS(1)
>>> x = {"name" : "Aakar", "age" : 14, "city" : "Noida"}
>>> type (x)
<class 'dict'>
❖ HOW TO ADD ELEMENTS IN A DICT:
❖ HOW TO DELETE OR REMOVE ELEMENTS IN A DICT:
We can remove a particular item from a dict by using
“pop” method. This method removes an item with a provided
key and returns the value.
The method “pop item” can be used to remove and return
an arbitrary item from the dict {key, value}.
All the items can be removed at once using the “clear”
method.
We can also use the “del” keyword to remove individual
items or the entire dict itself.
>>> x = {"Name": "Anushka", "Age": 14, "Class": 9}
>>> [Link]("Name")
'Anushka'
f) Sets: Python sets are a collection of data that are un-ordered
and un-indexed. In python sets are written are written with
{} curly brackets and it is an immutable data type.
❖ HOW TO ACCESS AN ITEM FROM A SET:
As we know that sets are unordered, the items have no
index. Thus, we can’t access items in our set with the help of
an index.
You can access with the help of loop and “in” operator
a = {100, 2000, 30, "Rebekah", 47.9}
for i in a:
print (i)
❖ HOW TO ADD ITEMS IN A SET:
As we know that sets are immutable data type so once a set
is created you cannot change its items but you can add new
items with the help of “add” and “update” method.
To add one item to a set use the add method.
>>> a = {100, 200, 300, "k"}
>>> [Link](1000)
>>> a
{100, 'k', 200, 1000, 300}
To add more than one items to a set use the update method.
>>> [Link]([2132,1281372,1973])
>>> a
{100, 'k', 200, 1000, 300, 2132, 1973, 1281372}
❖ HOW TO REMOVE ITEMS FROM A SET:
We can use “remove” or “discard” method.
You can also use the “pop” method to remove an item, but
this method will only remove the last item. Remember that
sets are unordered so you won’t know that which item will be
removed. The return value of the pop method is the removed
item.
The “clear” method empties the set items.
The “del” keyword allows any item to be deleted.
SET METHODS:
Python has a set of built in methods that you can use on
sets:
➢ Add It adds an element to the set.
➢ Clear Removes all the elements from the set.
➢ Copy Returns a copy of the set.
➢ Difference Returns a set containing the difference
between two or more sets.
➢ Difference_update Returns the items in the set that
are also included in another specified set.
➢ Discard Removes the specified items.
[Link] FUNCTIONS:
A function is a self-block of code. It can be called as a section of a
program that is written once and can be executed whenever required
in the program, thus making code re-usable. It is a sub-program that
works on data and produces some output.
Function Vs Methods:
A method refers to function that is part of a class. You can access it with an
instance or object of the class. A function doesn’t have a restriction. It just
refers to a stand – alone function. It means all methods are functions but
not all functions are methods.
❖ TYPES OF FUNCTIONS:
There are 3 types of functions:
Built-in functions
User defined functions (UDF)
o Use the keyword ‘def’ to declare the function.
o Add parameter to the function between the parentheses of
the function. End your line with a colon:
o Add statement that the function should execute.
Anonymous / Lambda functions
o There is no need to user ‘def’ keyword.
o We use ‘lambda’ keyword instead of ‘def’ keyword.
[Link] HANDLING:
There are types of functions for file handling:
• w write only
• wb write in binary format
• w + read and write
• wb+ read and write in binary format
• r read only
• rb read in binary format
• r+ read and write
• rb+ read and write in binary format
• a append
• ab append in binary format
• a+ append and read
• ab+ append and read in binary format
#write a le
f = open ("[Link]", "w")
[Link]("My le. ")
[Link]()
#reading a le
f = open ("[Link]", "w")
info = [Link]()
print (info)
#renaming a le
import os
[Link]("[Link]", "[Link]")
#Deleting a le
import os
fi
fi
fi
fi
fi
[Link]("[Link]")
#Creating a folder
import os
[Link]("June 17")
#Deleting a folder
import os
[Link]("June 17")
[Link] HANDLING:
try:
a = int(input("Enter rst number: "))
b = int(input("Enter second number: "))
c = a/b
print ( f "Result is {c}")
except:
print ("Invalid Input")
try:
a = int(input("Enter rst number: "))
b = int(input("Enter second number: "))
c = a/b
print ("Result is", c)
except Exception as E:
print (E)
[Link] (OBJECT-ORIENTED PROGRAMMING
LANGUAGE):
❖ FEATURES OF OOPS:
Class It’s a collection of similar types of objects. It’s a blueprint of
fi
fi
an object.
Object
class Originals:
x = 100
y = "Welcome"
z = 100.25 #data member
def Elijah(self):
print ("Elijah is a man of his word. He always sticks to what he says.")
def Rebekah(self):
print ("Rebekah is a girl who is Elijah's sister.")
def Klaus(self):
print ("Klaus is Elijah's and Rebekah's brother. He is a brave man. ")
#Constructor -> is a special type of function and this function executes
implicitly .
#To share any common information/ task for each and every object then we
use this concept.
class originals:
def __init__ (self):
print ("This class is about The Original Siblings, who vowed to stay
together Always & Forever! ")
def elijah(self):
print ("Elijah is a man of his word. He always sticks to what he says.")
def rebekah(self):
print ("Rebekah is a girl who is Elijah's sister. She is a strong lady. ")
def klaus(self):
print ("Klaus is Elijah's and Rebekah's brother. He is the brave immortal
alpha hybrid whom everyone fears... ")
#Constructor -> is a special type of function and this function
executes implicitly.
#To share any common information/ task for each and every object
then we use this concept.
Polimorfizm {One name many forms} There are two ways for
achieving it in python:
o Method Overloading / Function Overloaing Whenever you
have multiple funcitons with a same name in a single class
#Function overloading
class student():
def st(self):
print ("Aakar ")
def st(self):
print ("Vitthal ")
def st(self):
print ("Anu ")
o Method overriding Whenver you have multiple functions with
same name name in two diff classes, then u use this. ‘Super’
keyword is used.
super().<(def)>
#Function Overriding
class Anu():
def TO(self):
print ("It is the story of the Michaelsons... ")
def TVD(self):
print ("It is the story of the Salvatores... ")
class Avyu(Anu):
def TO(self):
print ("Family... ")
super().TO()
def TVD(self):
print ("Colleagues... ")
Inheritance Whenever you want to make a relationship between
two or more classes thn v use this method.
In Python we use five types of inheritance:
Single inheritance 1—2
Multi-level inheritance 1—2—3
Multiple multi is to one
Hierarchical one to multi
Hybrid
Encapsulation It is just the implementation of class.
✓for security and easily usable.
Abstraction Hiding the complexity and showing the
functionality is known as abstruction.
HOW TO ACCESS PUBLIC, PROTECTED AND PRIVATE
VARIABLES
Public <object>.<variable>
Protected <object>._<variable>
Private <object>._<class name>__<variable>
[Link]-THREADING:
thread object run(start)
[Link] SENDING PROGRAM:
import smtplib
server = [Link] ("[Link]", 587)
[Link]()
[Link]("cross.anu18@[Link]", "PWD")
[Link]("cross.anu18@[Link]",
"gaurvitthal330@[Link]", "Hi")
print ("Your mail successfully sent! ")
[Link]:
Max scrn Can’t maximize....
[Link](height = 400, width = 400)
Min scrn Can’t minimize..
[Link](height = 400, width = 400)
Geometry scrn To give default size
[Link] ("500x500")
Color [Link] gure (background = "Aqua")
Delete old data [Link](0, "end")
Width padx = 22
Height pady = 22
fi
[Link] IN GUI:
#Calc in GUI
from tkinter import*
v = Tk()
[Link]("Calculator by Anushka G.")
r = Entry(v, font = ("Gabriola", 30, "bold"), bg = "dark blue", fg = "aqua", bd = 10 )
[Link](columnspan=4)
#1st row
B1 = Button(v, text = "1",font = ("Gabriola", 40, "bold"), bg = "blue", fg = "violet",
bd = 10, padx = 4)
[Link](row=1, column=0)
B2 = Button(v, text = "2",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10, padx = 2 )
[Link](row=1, column=1)
B3 = Button(v, text = "3",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10, padx = 2 )
[Link](row=1, column=2)
B4 = Button(v, text = "C",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"red", bd = 10 )
[Link](row=1, column=3)
#2nd row
B5 = Button(v, text = "4",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=2, column=0)
B6 = Button(v, text = "5",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10, padx = 2 )
[Link](row=2, column=1)
B7 = Button(v, text = "6",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=2, column=2)
B8 = Button(v, text = "=",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"green", bd = 10, padx = 2)
[Link](row=2, column=3)
#3rd row
B9 = Button(v, text = "7",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=3, column=0)
B10 = Button(v, text = "8",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=3, column=1)
B11 = Button(v, text = "9",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=3, column=2)
B12 = Button(v, text = "x",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10, padx = 2 )
[Link](row=3, column=3)
#4th row
B13 = Button(v, text = "0",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=4, column=0)
B14 = Button(v, text = "+",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=4, column=1)
B15 = Button(v, text = " /",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=4, column=2)
B16 = Button(v, text = " -",font = ("Gabriola", 40, "bold"), bg = "dark blue", fg =
"violet", bd = 10 )
[Link](row=4, column=3)
[Link]()
[Link] EXPRESSION:
Regular expression is a special sequence of characters that helps you
match/find other strings or set of strings using a specialised syntax
held in a pattern. They are widely used in UNIX world. The module RE
provides full support for regular expression in python.
REGULAR EXPRESSION FUNCTIONS
Find all -> Returns a list conataining all matches.
Search -> Returns a match object if there is a match
anywhere in the string.
Split -> Returns a list where the string has been split at
each match.
#Regular expression
import re
x = "Welcome to python classes"
x2 = re. ndall( "[a-m]", x ) #sq brackets for list
print (x2)
# \ for digits
y = "We are friends since 2010!"
y2 = re. ndall( "\d", y )
print (y2)
# . for speci c objs.
z = "Welcome to python classes"
z2 = re. ndall( "py...n", z ) #sq brackets for list
print (z2)
[Link] PROCESSING:
Image processing is a method performed for operations
on an image, in order to get an enhanced image or
extract some useful information from it. It is a type of
processing in which input is an image and output maybe
an image or characteristics of an image. PIL [Python
Imaging Library] or Pillow is used. It performs basic
operations on images like creating thumbnails, resizing
images, conversion between different le formats.
from PIL import Image
myimg = [Link]("[Link]")
[Link](25).show()
fi
fi
fi
fi
fi