Opening Hours :7AM to 9PM
class Addition: def add(self): x=10 y=20 z=30
Binding of attributes and behaviors in a single container .In Python language it can be achieved by 'class' keyword.
class:
'class' is container which is collection of variable and methods (or) it is a blueprint of the object.
Syntax:
class ClassName: def methodname(self): list of variables .. .. .. ... ... ...in the above syntax class is keyword.
Variable:
Variable is an identifer whose value can can be changed.
Example:
x=10;
x=20;
In Python language these variable are classified into following types
1.Local variable
2.Global variable
3.Formal variable
4.Block variable
Local variable:
If any variable declare with in method or constructor.
Global variable
If any variable declare outside of the class.
Formal variable
If any variable declare with in method signature or constructor signature.
Block variable
If any variable declare with in block(if block ,for block ete..)
x=10 #Global Variable class Demo: def add(self,y):#Formal Variable z=20 #Local Variable if(condition): p=30 #BLock Variable
x=12 #global Varaible class Rain: def myfun(self): y=10 #local Variable print("Local Varialble of myfun ",y) print("Global Varialble of myfun ",x) def mydisp(self): z=20; #local Variable print("Global Varialble of mydisp ",x) #print(y) Here y is local Varialbe of myfun print("Local Varialble of mydisp ",z) if __name__=="__main__": r=Rain() r.myfun() r.mydisp()
Method is a collection of statements used to perform specific operation.
def methdname(self,list of parameters/no parameters): .... ... ..In the above syntax def is a method Defination
def methdname(self): .... ... ..Parametarized Method
def methdname(self,variable1,variable2): .... ... ..
class Maxnum: def max(self): x=10 y=20 if(x>y): print("x is max") else: print("y is max") if __name__=="__main__: m=Maxnum() m.max()
class Maxnum: def max(self): x=int(input("Enter x Value")) y=int(input("Enter y Value")) if(x>y): print("x is max") else: print("y is max") if __name__=="__main__: m=Maxnum() m.max()
class Maxnum: def max(self,x,y): if(x>y): print("x is max") else: print("y is max") if __name__=="__main__: m=Maxnum() m.max(10,20)
class Maxnum: def max(self,x,y): if(x>y): print("x is max") else: print("y is max") if __name__=="__main__: m=Maxnum() x=int(input("Enter x Value")) y=int(input("Enter y Value")) m.max(x,y)
class Maxnum: def max(self): x=10 y=20 if(x>y): return("x is max") else: return("y is max") if __name__=="__main__: m=Maxnum() s=m.max() print(s)
class Maxnum: def max(self): x=int(input("Enter x Value")) y=int(input("Enter y Value")) if(x>y): return("x is max") else: return("y is max") if __name__=="__main__: m=Maxnum() s=m.max() print(s)
class Maxnum: def max(self,x,y): if(x>y): return("x is max") else: return("y is max") if __name__=="__main__: m=Maxnum() s=m.max(10,20) print(s)
class Maxnum: def max(self,x,y): if(x>y): return("x is max") else: return("y is max") if __name__=="__main__: m=Maxnum() x=int(input("Enter x Value")) y=int(input("Enter y Value")) s=m.max(x,y) print(s)
class Maxnum: def max(self): x=10 y=20 if(x>y): return x else: return y if __name__=="__main__: m=Maxnum() s=m.max() print(s)
class Maxnum: def max(self): x=int(input("Enter x Value")) y=int(input("Enter y Value")) if(x>y): return x else: return y if __name__=="__main__: m=Maxnum() s=m.max() print(s)
class Maxnum: def max(self,x,y): if(x>y): return x else: return y if __name__=="__main__: m=Maxnum() s=m.max(10,20) print(s)
class Maxnum: def max(self,x,y): if(x>y): return x else: return y if __name__=="__main__: m=Maxnum() x=int(input("Enter x Value")) y=int(input("Enter y Value")) s=m.max(x,y) print(s)
class Factorial: def fact(self): x=1 f=1 n=int(input("enter n value")) while(x<=n): f=f*x x=x+1 print(f) if __name__=="__main__": ff=Factorial() ff.fact()
class Factorial: def fact(self,n): x=1 f=1 while(x<=n): f=f*x x=x+1 print(f) if __name__=="__main__": ff=Factorial() n=int(input("enter n value")) ff.fact(n)
class Factorial: def fact(self): x=1 f=1 n=int(input("enter n value")) while(x<=n): f=f*x x=x+1 return(f) if __name__=="__main__": ff=Factorial() s=ff.fact() print(s)
class Factorial: def fact(self,n): x=1 f=1 while(x<=n): f=f*x x=x+1 return(f) if __name__=="__main__": ff=Factorial() n=int(input("enter n value")) s=ff.fact(n)