-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses and objects.py
More file actions
66 lines (47 loc) · 1.38 KB
/
Copy pathclasses and objects.py
File metadata and controls
66 lines (47 loc) · 1.38 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
class person:
name="pratham"
occupation = "Student"
networth = 10
def info(self):
print(f"{self.name} is a {self.occupation}")
a = person()
b = person()
c = person()
d = person()
a.name = "Shubham"
# print(a.name)
a.occupation = "ca"
# print(a.occupation)
a.info()
b.name = "Nitin"
b.occupation="accountant"
c.name = "Neel"
c.occupation="developer"
d.name = "Nitika"
d.occupation="engneer"
a.info()
b.info()
c.info()
d.info()
# Python Class and Objects
# A class is a blueprint or a template for creating objects, providing initial values for state (member variables or attributes), and implementations of behavior (member functions or methods). The user-defined objects are created using the class keyword.Creating a Class:
# Let us now create a class using the class keyword.
# class Details:
# name = "Rohan"
# age = 20
# Creating an Object:
# Object is the instance of the class used to access the properties of the class Now lets create an object of the class.
# self parameter
# The self parameter is agreference to the current instance of the class, and is used to access variables that belongs to the class.
# It must be provided as the extra parameter inside the method definition.
# Example:
# class Details:
# name =
# "Rohan"
# age = 20
# def desc(self):
# print( "My name is", self.name,
# "and I'm", self.age,
# "years old.")
# obj1 = Details()
# obj1. desc()