0% found this document useful (0 votes)
5 views31 pages

Python Varibles

The document provides a comprehensive overview of Python programming concepts, including variable declaration, data types, string manipulation, collections (lists, tuples, sets, dictionaries), operators, control flow (conditional statements and loops), functions, and object-oriented programming. It includes examples of each concept to illustrate their usage. The document serves as a tutorial for beginners to understand and apply Python programming effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views31 pages

Python Varibles

The document provides a comprehensive overview of Python programming concepts, including variable declaration, data types, string manipulation, collections (lists, tuples, sets, dictionaries), operators, control flow (conditional statements and loops), functions, and object-oriented programming. It includes examples of each concept to illustrate their usage. The document serves as a tutorial for beginners to understand and apply Python programming effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

"""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)

"""multiword varible names"""

# camelcase

# each word except the first starts with the capital letter

# myVariableName

# pascalcase

# each word start with the capital letter

# MyVariableName

# snakecase

# each word is separated by an underscore character

# my_variable_name

"""many values to multiple variables"""

# 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())

#capitalize the first letter of first word in the string

#print(x.title())

#capitalize the first letter of each word

# 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'

# z=y.replace(x,"how are you")

# print(z)

# x='new bike'

# y='bike'

# z=x.replace(y,"car")

# print(z)

# """string formatting"""

# x='my name is {} and am from {}'.format("benchamin","mekkadampu")

# print(x)

# x='ben'

# y='ernakulam'

# c='my name is {} and am from {}'.format(x,y)

# print(c)

# v= input("enter name:")

# n= input("enter palce:")

# x='my name is {} and am from {}'.format(v,n)

# 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"""

# r.sort() #arrange in alphabetic order

# print(r)

# r.sort(reverse=True)
# print(r)

# """pop"""

# r.pop() #removes the last element

# print(r)

# r.pop(3)

# print(r)

# del r[4]

# print(r)

# """clear"""

# r.clear() #empty the list

# 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.symmetric_difference(b)) #unique elements

# print(v.isdisjoint(b)) #returns true if both the sets are different

# print(v.issuperset(b)) #checking every elements in 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)

# l.update({"name":"jd"}) #updating items

# print(l)

# l["collage"]="bps"

# print(l)

# l.update({"age":12}) #add items

# print(l)

# l.pop("age") #remove the item

# print(l)

# l.popitem() #removes the last item

# print(l)

# l.clear() #empty the dictionary

# 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) #it will avoid decimals-floor divison

# 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

# print(m<9 and m>2)

# print(m<5 or m>3) #returns true if either one statement is true

# print(not(m<5 or m>3)) # reverse the result

# """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)

# c=input("enter the numbers:")

# 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 :

# print("c is postive number")

# if c<0 :

# print("c")

# else:

# print("c is greater than o")

# n=56

# if n>0 :

# print(" n is negative number")

# else:

# print("n is positive number")

# m=12

# if m==0:

# print("m is 0")

# elif m>0:

# print(" m is greater than 0")

# elif m<0:

# print(" m is less than 0")

# else:

# print(" m is true")

# """nest if"""
# k=1

# if k<10:

# if k>12:

# print("k is less than 0")

# else:

# print(" k is greater than 0")

# else:

# print(" k is true")

# """loop"""

# """forloop"""

# o=[12,45,78]

# for x in o:

# print(x)

"""forloop with break statement"""

# o=[12,45,78,98,75,78,67]

# for x in o:

# if x==75:

# break

# print(x)

"""forloop with continue statement"""

# o=[12,45,78,98,75,78,67]

# for x in o:

# if x==75:

# continue

# print(x)

"""forloop with range"""

# 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)

"""whileloop with break statement"""

# u=0

# while u<=10:

# u+=1

# if u>6:

# break

# print(u)

"""whileloop with continue statement"""

# u=0

# while u<=10:

# u+=1

# if u==6:

# continue

# print(u)

# for x in range(1,31):

# if x%3==0 and x%5==0:

# print("fungame")

# elif x%5==0:

# print("game")

# elif x%3==0:

# print("fun")

# else:
# print(x)

#"""functions"""-a block of code which is executed only when it is called

#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):

# print(name," is from ",place," he is",age)

# student("benchamin",21,"muvattupuzha")

# def sum(a,b):

# print(a+b)

# sum(2,3)

# """function with return statement"""

# 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))

# x=lambda a:"even" if a%2==0 else "odd"

# 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):

# print(self.name+"is on the road")

# 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):

# print(self.name+"is studying biology")

# 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):

# print(self.name,"is studying geography")

# 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:

# def __init__(self, name, year):

# self.name = name

# self.year = year

# def year(self):

# print(self.name, "is since")

# class Bikes:

# def __init__(self, color, model):

# self.color = color

# self.model = model

# def model(self):

# print(self.color, "is skyline") # Fixed the print statement here

# class Vehicle1(Cars, Bikes):

# def __init__(self, name, year, color, model):

# Cars.__init__(self, name, year)

# Bikes.__init__(self, color, model)

#
#

# c1 = Vehicle1("nissan", 2021, 'red', 'sdfg')

# print(c1.name, c1.year, c1.color, c1.model)

# """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)

# y=math.pow(6,7) #first number rise to second number

# 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:

# y=int(input("enter first number:"))

# z=int(input("enter second number:"))

# v=y/z

# except ZeroDivisionError:

# print("you cant divide by zero")

# except ValueError:

# print("enter only numbers")

# except Exception:

# print("something went wrong")

# else:
# print(v)

# finally:

# print("this will always execute")

"""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())

"""write and create files"""

"""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

n="hello how are you 6754"

b=re.findall("[0-5][0-9]",n) #return the number of the letters

print(b)

"""search"""

# import re

# n="hello how are you"

# b=re.search("l",n)

# print(b)

"""split"""

# import re

# n="hello how are you"

# b=re.split("a",n)

# print(b)

"""sub"""

# import re

# n="hello how are you"

# b=re.sub("h","k",n)

# print(b)

You might also like