-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classes and objects.py
61 lines (48 loc) · 1.24 KB
/
Classes and objects.py
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
'''
Classes and objects
To create an object we must define its structure or blueprint by using the class
and when we create the variables of this class is it called as an object
syntax of class:
class className:
# Data members
.
.
.
memberFunctions()
.
.
.
To ctreate the object
objectName = className()
class Addition:
def add(self,x,y):
self.num1 = x
self.num2 = y
return self.num1+self.num2
obj1 = Addition()
res = obj1.add(4,7)
print('Num1 = ', obj1.num1)
print('Num2= ',obj1.num2)
print('Addition = ', res)
'''
class Student:
def getData(self):
self.RN = int(input('Enter the Roll num: '))
self.name = input('Enter the name: ')
self.dob = input('Enter the date of birth: ')
self.email = input('Enter the email address: ')
self.mob = int(input('Enter the mob No: '))
def showData(self):
print(f'Roll no: {self.RN}\nName: {self.name}\nDate od Birth: {self.dob}\nEmail: {self.email}\nMobile: {self.mob}')
stud1 = Student()
stud1.getData()
stud1.showData()
stud2 = Student()
stud2.RN=5
stud2.name="Jill"
stud2.dob = "02/05/1994"
stud2.email = "[email protected]"
stud2.mob = 3214569870
stud2.showData()
print(stud2.RN)
print(stud2.name)