Python Varibles
Python Varibles
# x='benchamin'
# print(x)
# y=12
# print(y)
# print(type(x))
# print(type(y))
# myvar='dev'
# my_var=13
# MYVAR=76
# myVar='jj'
# _my_var='tuy'
# myvar90=7
# print(myvar)
# print(MYVAR)
# camelcase
# each word except the first starts with the capital letter
# myVariableName
# pascalcase
# MyVariableName
# snakecase
# my_variable_name
# x,y,z=56,76,89
# print(x)
# print(y)
# print(z)
# print(x,y,z)
# print(y,z,x)
# x=y=z=2
# print(x)
# print(y)
# """concatienation"""
# x='hello '
# y='world'
# print(x,y)
# print(x+y)
# """python datatypes-int,float,complex,string,list,set,tuple,dictionary,boolen"""
# x=4
# y=1.2
# z=1j
# print(x)
# print(y)
# print(z)
# print(type(y))
# print(type(z))
# a=float(x)
# print(a)
# w=int(y)
# print(w)
# c=complex(x)
# print(c)
# b=int(z)
# print(b)
# n=float(z)
# print(n)
"""strings"""""
"""slicing strings"""
x='Benchamin Benoy'
# print(x[2:7])
# print(x[5])
# print(x[-3])
# print(x[-5:-3])
# print(x[:7])
# print(x[:-3])
# print(x[4:])
# print(x[6:])
# print(len(x))
# print(x.upper())
# print(x.lower())
# print(x.swapcase())
# print(x.capitalize())
#print(x.title())
# print(x.startswith("B"))
# print(x.endswith("m"))
# print(x.count("n"))
# x='***benchamin***'
# print(x.strip("*"))
# print(x.rstrip("*"))
# print(x.lstrip("*"))
# x='benchamin benoy'
# print(x.rstrip("benoy"))
# print(x.lstrip("benchamin"))
# """partition"""
# x="helloworldtoday"
# print(x.partition("world"))
# x='how are you'
# print(x.partition("are"))
# """split"""
# x='hello#world%today'
# print(x.split("#"))
# x='hello '
# y='world'
# print(x,y)
# print(x+y)
# x='world'
# y='hello world'
# print(z)
# x='new bike'
# y='bike'
# z=x.replace(y,"car")
# print(z)
# """string formatting"""
# print(x)
# x='ben'
# y='ernakulam'
# print(c)
# v= input("enter name:")
# n= input("enter palce:")
# print(x)
# """boolean"""
# print(10>6)
# print(7<1)
# """sequential datatypes or collectors"""
# """list"""
# y=['ben',45,1.8,True,False,19>7]
# print(y)
# r=['red','blue','yellow','green','white','brown','brown']
# r[0:3]=["somecolors"]
# print(r)
# print(r)
# print(len(r))
# print(r[4])
# print(r[1:4])
# print(r[-3:-1])
# print(r[4:])
# print(r[:5])
# print(r[-3])
# r[0]="black"
# print(r)
# r[4]="pink"
# print(r)
# print(y+r)
# """extend"""
# y.extend(r)
# print(y)
# r.extend(y)
# print(r)
# r.append("purple")#append-adding items
# print(r)
# """sort"""
# print(r)
# r.sort(reverse=True)
# print(r)
# """pop"""
# print(r)
# r.pop(3)
# print(r)
# del r[4]
# print(r)
# """clear"""
# print(r)
#print(type(r))
# """tuple"""
# x=('red',12,1.5,True,False,'brown','yellow')
# print(x)
# print(len(x))
# print(type(x))
# y=('blue',13,2.5)
# print(x+y)
# print(x,y)
# print(x[2:5])
# print(x[-5:-3])
# z=list(x)
# print(z)
# z.append('white')
# print(z)
# z.pop()
# print(z)
# z.clear()
# print(z)
# n=tuple(z)
# print(n)
# z=('white','blue','green','brown','black','yellow')
# (car,*bike,plane)=z
# print(car)
# print(bike)
# print(plane)
# print(bike)
# print(car)
# print(z*2)
# print(z*3)
# """set"""
# v={'basil',1,0,True,1.4,'kid','era',5,6,'king'}
# print(v)
# print(len(v))
# print(type(v))
# v.add("glue")
# print(v)
# v.remove("basil")
# print(v)
# v.discard("kid")
# print(v)
# b={'era',5,6,'king'}
# print(v.union(b))
# print(v.intersection(b))
# print(v.issubset(b))
# print(v)
# print(b.issubset(v))
# """dictionary"""
# l={"name":"ben","place":"ernakulam"}
# print(l)
# print(len(l))
# print(type(l))
# print(l["name"])
# print(l["place"])
# print(l.keys())
# print(l.values())
# l["place"]="piravom"
# print(l)
# print(l)
# l["collage"]="bps"
# print(l)
# print(l)
# print(l)
# print(l)
# print(l)
# """python operators"""
# """arithematic operators"""
# a=10
# b=9
# print(a+b)
# print(a-b)
# print(a/b)
# print(a*b)
# print(a%b) #modulus-remainder
# print(a**b)
# """assignment operators"""
# a+=3
# print(a)
# a-=5
# print(a)
# a*=3
# print(a)
# a/=2
# print(a)
# """comparison operators"""
# print(a==b)
# print(a!=b)
# print(a<b)
# print(a>b)
# print(a<=b)
# print(a>=b)
# """logical operators"""
# m=6
# print(m<4 and m>8) #returns true if both the statements are true
# """identity operators"""
# n=["jki",12,7,9]
# b=["jki",12,7,9]
# h=n
# print(n is h)
# print(b is n)
# print(n is not h)
# print(b is not h)
# """membership operator"""
# v=["blue","black","yellow","white"]
# print("black" in v)
# print("black" not in v)
# tup = tuple(c)
# print('tuple:',tup)
# b=list(c)
# print(b)
# v="ben"
# n="nun"
# print(v,n)
# m="nun"
# print(n.count(("n")))
# h='bEnchaMin'
# print(h.swapcase())
#l=[[1,3],[5,7],[9,11]]
#o=[[2,4],[6,8],[10,12,14]]
# p=l[0]+o[0],l[1]+o[1],l[2]+o[2]
# print(list(p))
# m=zip(l,o)
# c=list(m)
# print(c)
# g=[[2],[0],[1,3],[0,7],[9,11,[13,15,17]]]
# g.sort(key=None)
# g.sort(key=len)
# print(g)
# n=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
# n[0].sort(reverse=True)
# print(n)
# d=[(2,5),(1,2),(4,4),(2,3)(2,1)]
# """conditional statements"""
# c=87
# if c>0 :
# if c<0 :
# print("c")
# else:
# n=56
# if n>0 :
# else:
# m=12
# if m==0:
# print("m is 0")
# elif m>0:
# elif m<0:
# else:
# print(" m is true")
# """nest if"""
# k=1
# if k<10:
# if k>12:
# else:
# else:
# print(" k is true")
# """loop"""
# """forloop"""
# o=[12,45,78]
# for x in o:
# print(x)
# o=[12,45,78,98,75,78,67]
# for x in o:
# if x==75:
# break
# print(x)
# o=[12,45,78,98,75,78,67]
# for x in o:
# if x==75:
# continue
# print(x)
# for x in range(5):
# print(x)
# for x in range(5,16):
# print(x)
# for x in range(20,10,-1):
# print(x)
# for x in range(0,-24,-2):
# print(x)
"""whileloop"""
""""""
# u=0
# while u<=10:
# u+=1
# print(u)
# u=0
# while u<=10:
# u+=1
# if u>6:
# break
# print(u)
# u=0
# while u<=10:
# u+=1
# if u==6:
# continue
# print(u)
# for x in range(1,31):
# print("fungame")
# elif x%5==0:
# print("game")
# elif x%3==0:
# print("fun")
# else:
# print(x)
#without paraameter
# def dud():
# print("hello dud")
# print("hjdj")
# dud()
# dud()
# #with parameter
# def sum(mssg):
# print("sum is greater",mssg)
# sum("jhsh")
# def gui(name):
# print("hello",name)
# gui("benchamin")
# def student(name,age,place):
# student("benchamin",21,"muvattupuzha")
# def sum(a,b):
# print(a+b)
# sum(2,3)
# def sum():
# return(10+20)
# print(sum())
# def square(a):
# return(a**2)
# print(square(4))
"""arbitary arguments"""
# def gun(x,y,*args):
# print(args)
# return x+y
# print(gun(1,2,3,4,5,6))
"""keyword arguments"""
# def vbn(**kwargs):
# print(kwargs)
# vbn(name="ben",place="aluva",age=45)
"""recursive function"""
# def bun(n):
# if n<=1:
# return n
# else:
# return n+bun(n-1)
# a=bun(10)
# print(a)
# def mun(n):
# if n<=1:
# return 1
# else:
# return n*mun(n-1)
# b=mun(5)
# print(b)
# x=int(input("enter a number:"))
# z=input("enter a operator:")
# y=int(input("enter a number:"))
# if z=="+":
# def sum():
# print(x+y)
# (sum())
# elif z=="-":
# def neg():
# print(x-y)
# (neg())
# elif z=="*":
# def mul():
# print(x*y)
# (mul())
# elif z=="/":
# def div():
# print(x/y)
# (div())
# """lambda function"""
# x=lambda a:a+10
# print(x(7))
# def sum():
# return (10+20)
# print(sum())
# v=lambda a,b:a+b
# print(v(3,8))
# print(x(9))
# p=[(2,5),(1,2),(4,4),(2,3),(2,1)]
# print(sorted(p,key=lambda n:(n[1],n[0])))
"""oops concept"""
# class Vehicles:
# def __init__(self,name,color,model):
# self.name=name
# self.color=color
# self.model=model
# car1=Vehicles("nissan","blue","gtr")
# print(car1.name,car1.color,car1.model)
# class Vehicles:
# def __init__(self,name,color,model):
# self.name=name
# self.color=color
# self.model=model
# def run(self):
# car1=Vehicles("nissan","blue","gtr")
# print(car1.name,car1.color,car1.model)
# car1.run()
# class Student:
# def __init__(self,name,place,collage):
# self.name=name
# self.place=place
# self.collage=collage
# def subject(self):
# boy1=Student("nandhu","piravom","bpc")
# boy1.name="dev"
# print(boy1.name,boy1.place,boy1.collage)
# boy1.subject()
# """local scope"""
# def myfunc():
# x=300
# def myinnerfunc():
# print(x)
# myinnerfunc()
# myfunc()
# """global scope"""
# x=300
# def myfunc():
# print(x)
# myfunc()
# """inheritance"""
# class Student:
# def __init__(self,name,place,age):
# self.name=name
# self.place=place
# self.age=age
# class Student1(Student):
# pass
# s1=Student1("ben","piravom",26)
# print(s1.name,s1.place,s1.age)
# class Student:
# def __init__(self,name,place,age):
# self.name=name
# self.place=place
# self.age=age
# def subject(self):
# class Student1(Student):
# pass
# s1=Student1("ben","piravom",26)
# print(s1.name,s1.place,s1.age)
# s1.subject()
"""single inheritance"""
"""multiple inheritance"""
# class Cars:
# def __init__(self,name,model):
# self.name=name
# self.model=model
# def year(self):
# print(self.name,"is since")
# class Bikes:
# def __init__(self,model,year):
# self.model=model
# self.year=year
# def model(self):
# print(self.model,"is v3")
# class Vehicle1(Cars,Bikes):
# def __init__(self,):
# cars1=Vehicle1("nissan","gtr")
# bikes1=Vehicle1("yamaha",2022)
# print(cars1.name,cars1.model)
# print(bikes1.model,bikes1.year)
# class Job:
# def __init__(self,name,year):
# self.name=name
# self.year=year
# def passed(self):
# print(self.name,"is passed")
# class Company:
# def __init__(self,name,year):
# self.name=name
# self.year=year
# def appoint(self):
# print(self.name,"is appointed")
# class Job1(Job,Company):
# def
# j1=Job1("ben",2001)
# j2=Job1("infopark",2008)
# print(j1.name,j1.year)
# print(j2.name,j2.year)
# j1.passed()
# j2.appoint()
# """multilevel inheritance"""
# class Grandfather:
# def __init__(self,gname,gage):
# self.gname=gname
# self.gage=gage
# class Father(Grandfather):
# def __init__(self,fname,fage,gname,gage):
# self.fname=fname
# self.fage=fage
# Grandfather.__init__(self,gname,gage)
# class Son(Father):
# def __init__(self,sname,sage,fname,fage,gname,gage):
# self.sname=sname
# self.sage=sage
# Father.__init__(self,fname,fage,gname,gage)
# def familyname(self):
# print(self.gname,self.gage,self.fname,self.fage,self.sname,self.sage)
# g1=Son("nhj",80,"hdy",45,"gry",20)
# g1.familyname()
# class Cars:
# self.name = name
# self.year = year
# def year(self):
# class Bikes:
# self.color = color
# self.model = model
# def model(self):
#
#
# """hierarchial inheritance"""
# class Fruits:
# def __init__(self,fname,ftype):
# self.fname=fname
# self.ftype=ftype
# class Apple(Fruits):
# pass
# class Orange(Fruits):
# pass
# f1=Apple("greenapple","small")
# f2=Orange("lemonorange","big")
# print(f1.fname,"is yummy")
# print(f2.fname,"is juicy")
"""polymorphism"""
# class Clothes:
# def __init__(self,color,size):
# self.color=color
# self.size=size
# def inter(self):
# print(self.color,"blue")
# class Shirts:
# def __init__(self,color,size):
# self.color=color
# self.size=size
# def inter(self):
# print(self.color,"white")
# class Denims:
# def __init__(self,color,size):
# self.color = color
# self.size = size
# def inter(self):
# print(self.color,"green")
# f2=Clothes("brown","small")
# f3=Shirts("yellow","medium")
# f4=Denims("black","small")
# for x in(f2,f3,f4):
# print(x.color,x.size)
# x.inter()
# class Clothes:
# def __init__(self,color,size):
# self.color=color
# self.size=size
# def inter(self):
# print(self.color,"blue")
# class Shirts(Clothes):
# pass
# class Denims(Clothes):
# def inter(self):
# print(self.color,"green")
# f2=Clothes("brown","small")
# f3=Shirts("yellow","medium")
# f4=Denims("black","small")
# for x in(f2,f3,f4):
# print(x.color,x.size)
# x.inter()
# """math module"""
# import math
# c=math.pi
# print(c)
# v=math.sqrt(16)
# print(v)
# b=math.gcd(64,76,12)
# print(b)
# n=math.lcm(45,98)
# print(n)
# m=math.sin(5)
# print(m)
# k=math.cos(9)
# print(k)
# l=math.tan(8)
# print(l)
# print(y)
# """minimum/maximum"""
# n=min(3,4,5,6,7)
# print(n)
# m=max(3,9,5,6)
# print(m)
# """date module"""
# import datetime
# j=datetime.datetime.now()
# b=datetime.datetime(2023,2,23)
# print(b)
# # print(j)
# # print(j.year)
# print(j.strftime("%b"))
# print(j.strftime("%B"))
# print(j.strftime("%Y"))
# print(j.strftime("%y"))
# print(j.strftime("%m"))
# print(j.strftime("%d"))
# print(j.strftime("%w"))
# print(j.strftime("%a))
# import don
# don.sum()
# """exception handling"""
# try:
# v=y/z
# except ZeroDivisionError:
# except ValueError:
# except Exception:
# else:
# print(v)
# finally:
"""encpasulation"""
"""public"""
# class Year:
# def __init__(self,month,day):
# self.month=month
# self.day=day
# def yer(self):
# print(self.month,"january")
# b1=Year("february","monday")
# b1.month="june"
# b1.yer()
"""private"""
# class Year:
# def __init__(self,month,day):
# self._month=month
# self.day=day
# def yer(self):
# print(self._month,"january")
# b1=Year("february","monday")
# b1.month="june"
# b1.yer()
# class Year:
# def __init__(self,month,day):
# self.__month=month
# self.day=day
# def yer(self):
# print(self.__month,"january")
# b1=Year("february","monday")
# b1.month="june"
# b1.yer()
"""file handling"""
"""read files"""
# b=open("demo.txt","r")
# print(b.read())
# b=open("demo.txt","r")
# print(b.read(10))
# b=open("demo.txt","r")
# print(b.readline())
# print(b.readline())
# print(b.readline())
# print(b.readline())
"""a=append"""
# f=open("demo.txt","a")
# f.write("gegehbdbdhhdhdhdhhdhdh")
# f.close()
# b=open("demo.txt","r")
# print(b.read())
"""w=overwrite existing contents"""
# f=open("demo.txt","w")
# f.write("boy")
# f.close()
# b=open("demo.txt","r")
# print(b.read())
# m=open("sample.txt","a")
# m.write("jegggu")
# m.close()
# m=open("sample.txt","r")
# print(m.read())
# import os
# os.remove("sample,txt")
# n=open("ben.txt","a")
# n.write("has a gtr")
# n.close()
# n=open("ben.txt","r")
# print(n.read())
# print(n.readline())
# import os
# os.remove("ben.txt")
"""json"""
# import json
# e='{"name":"ben","place":"piravom","college":"bpc"}'
# n=json.loads(e)
# print(n)
import json
# e={"name":"ben","place":"piravom","college":"bpc"}
# n=json.dumps(e)
# print(n)
"""regular expression"""
import re
print(b)
"""search"""
# import re
# b=re.search("l",n)
# print(b)
"""split"""
# import re
# b=re.split("a",n)
# print(b)
"""sub"""
# import re
# b=re.sub("h","k",n)
# print(b)