-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
94 lines (61 loc) · 2.55 KB
/
classes.py
File metadata and controls
94 lines (61 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# # classes -> classe like a blue print in your application
# # class Myclass: #class keyword used to create a class
# # x=10 # properties -> you create a variable inner the class is called properties
# # def myfun(): # you create a function inner the classes is called a method
# # print("method from class")
# # obj=Myclass()
# # print(obj.x)
# # class calculator:
# # def add(self,num1,num2):
# # print(num1+num2)
# # def sub(self,num1,num2):
# # print(num1-num2)
# # def mul(self,num1,num2):
# # print(num1*num2)
# # def div(self,num1,num2):
# # print(num1/num2)
# # math=calculator()
# # math.add(5,5)
# # math.sub(20,15)
# # math.mul(5,5)
# # math.div(10,2)
# # class myClass:
# # def __init__(self,name1,name2): #this is a constructor
# # self.fname=name1 #self represent a class name(this class)
# # self.lname=name2
# # def fullname(self):
# # return 'my name is '+self.fname+self.lname
# # obj=myClass("sujay","selvan")
# # print(obj.fname)
# # print(obj.lname)
# # print(obj.fullname())
# # # you can change a value after the constructor create or after object create
# # obj.fname="ajith"
# # obj.lname="kumar"
# # print(obj.fullname()) #my name is ajithkumar
# # # you also delete a properties
# # del obj.fname
# # print(obj.fullname()) #getting a error because fname was deleted
# # # you want to declare a empty class used a self keyword
# # class empty:
# # pass
# # inheritance*********************************
# # syntax only change other than all are same like as js
# class Parent:
# def __init__(self,fname,lname):
# self.fname=fname
# self.lname=lname
# def fullname(self):
# return self.fname+self.lname
# class child(Parent): #the way of extents or merge or combine a two classes
# def father(self):
# return 'my father name is '+self.fullname()
# obj=child("senthamil","selvan") # create a object for child class and this object can access a parent and child classes properties and method
# obj1=Parent("ajith","kumar") # create a object for parent class only this object only access a our properies and method can't access a child class method and properties
# print(obj.father())
# print("my full name is"+obj.fullname())
# print(obj1.fullname())
# #child class also create a constructor and should allownce a parent class
# class child(Parent):
# def __init__(self, fname, lname):
# super().__init__(fname, lname) #you can use super or Parent class name both are do same