Posts

Update

 ('ram', 'male',401) ('sam', 'male',458) ('priya', 'female', 456) ('ram', 'male',401) ('sam', 'male',456) ('priya', 'female',500) Update Successfully (ram', 'male',401) ('sam', 'mark',458) ('priya', 'male',500) ('sam', 'male',458) ('Priya', 'female',500) Delete Sucessfully (sam', 'male',458) ('priya', 'female',500) Drop Successfully

Select

 Select all records from table ('jebaroshan', '24UCS023',89,67) ('ram', '24UCS034',90,87) ('Sam', '24UCS045', 85, 79) Select particular columns ('jebaroshan', 89) ('ram',90) ('Sam',85) Select particular rows ('ram', '24UCS034,90, 87) Select particular rows and columns ('ram', '24UCS034') ('Sam', '24UCS045')

Different Modes in file handling

f=open("file1.txt","w") while(True):   t=input("t: ")   if(t== "@"):     print("The End")     break   else:     f.write(t)     f.write("\n") f.close() f=open("file1.txt","r") x=f.read () print (x) f = open(" file1.txt","a") while(True):   t= input("t:")   if(t == "@"):      print("The End")      break   else:      f.write(t)      f.write("\n") f.close() f=open("file2.txt","x") while(True):   t=input(":")   if(t=="@"):     print ("The End")     break   else:     f.write (t)     f.write("\n") f.close ()

Writing data to the file

source=input("Enter the source file:") f=open(source,"r") upper=0 lower=0 number=0 lines=0 spl=0 char=0 while(True): ch=f.read(1)     if(ch==''):         break     char+=1     if(ch=='\n'):         lines+=1 elif(ch>='0' and ch<='9'):         number+=1 elif(ch.isupper()):         upper+=1 elif(ch.islower()):         lower+=1     else: spl+=1 print("The number of characters:",char) print('The number of uppercase letters:',upper) print("The number of lowercase letters:",lower) print("The number of lines:",lines) print("The number of numeric characters:",number) print("The number of special characters:",spl)

Reading data to the file

source=input("Enter the source file:") f=open(source,"r") upper=0 lower=0 number=0 lines=0 spl=0 char=0 while(True): ch=f.read(1)     if(ch==''):         break     char+=1     if(ch=='\n'):         lines+=1 elif(ch>='0' and ch<='9'):         number+=1 elif(ch.isupper()):         upper+=1 elif(ch.islower()):         lower+=1     else: spl+=1 print("The number of characters:",char) print('The number of uppercase letters:',upper) print("The number of lowercase letters:",lower) print("The number of lines:",lines) print("The number of numeric characters:",number) print("The number of special characters:",spl)

Types of arguments in python

1. Default arguments 2. Keyword arguments 3. Positional arguments 4. Arbitrary positional arguments 5. Arbitrary keyword arguments Default arguments : Default arguments are values that are provided while  defining functions. The assignment operator = is used to assign a default  value to the argument. Ex: def add(a,b=5,c=10):  return (a+b+c) x=add(14) print(x) Keyword Arguments : Functions can also be called using keyword arguments of the form kwarg=value.During a function call, values passed through arguments don’t need to be in the order of parameters in the function definitions. Ex : def add(a,b,c): return (a+b+c) m=add(b=10,c=15,a=20) print(m) Positional Arguments : arguments are passed in order one after the other, those  arguments are called the "Positional arguments." Eg : def add(a,b,c):  return (a+b+c) print (add(10,20,30)) Arbitrary Positional Argument : For arbitrary positional argument, an asterisk (*) is placed  before a parameter in function d...

Write a python program for swapping the first and last element of the list using function

Coding: def swap(x):     x[0],x[-1]=x[-1],x[0]     return(x) list=[] r=int(input("Enter the range of list : ")) for i in range(r):     n=int(input("Enter the number : "))     list.append(n) print("List Before Swapping : ",list) r=swap(list) print("List After Swapping : ",r) Output: Enter the range of list : 5 Enter the number : 23 Enter the number : 90 Enter the number : 34 Enter the number : 51 Enter the number : 67 List Before Swapping :  [23, 90, 34, 51, 67] List After Swapping :  [67, 90, 34, 51, 23]