Visitar URL original
Update AttributesandMethods.md · VenkatAdd/PythonScript@ade64e3 · GitHub
Skip to content

Commit ade64e3

Browse files
authored
Update AttributesandMethods.md
1 parent ef0a29d commit ade64e3

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

‎Class/AttributesandMethods.md‎

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
## Attributes and Methods
22

33

4-
## Atributes
4+
## Attributes
55
- variable inside a class are called attributes.
66
- A class attribute is a Python variable that belongs to a class rather than a particular object.
7-
- It is shared between all the object of the class.
8-
- Atrributes are defined outside the constructor methods.
7+
- It is shared between all the objects of the class.
8+
- Attributes are defined outside the constructor methods.
99

1010
Syntax:
1111
```python
1212
class <ClassName>:
13-
variablename=value
13+
variablename=value
1414
```
1515
Example:
1616
```python
1717
class Person:
18-
#Initialize Attributes
19-
name="python"
20-
age=25
18+
#Initialize Attributes
19+
name="python"
20+
age=25
2121
```
2222
### How to get values of Class attribute using class objects?
2323

24-
- for accessing class attributes use classname and dot(.) notation
24+
- for accessing, class attributes use class name and dot(.) notation
2525

2626
Syntax:
2727
```python
@@ -32,9 +32,9 @@ Example:
3232
```python
3333
#Initilize class
3434
class Person:
35-
#Initialize Attributes
36-
name="python"
37-
age=25
35+
#Initialize Attributes
36+
name="python"
37+
age=25
3838

3939
#initialize the class object
4040
p1=Person()
@@ -49,6 +49,11 @@ age=p1.age
4949
print(age)
5050
#Result:25
5151
```
52+
Output:
53+
```
54+
python
55+
25
56+
``
5257
5358
### Modify Class Attributes using Class object
5459
- To modify class attributes use normal assignment(=) operator with class object and attributes name
@@ -62,9 +67,9 @@ Example:
6267
```python
6368
#Initilize class
6469
class Person:
65-
#Initialize Attributes
66-
name="python"
67-
age=25
70+
#Initialize Attributes
71+
name="python"
72+
age=25
6873

6974
#initialize the class object
7075
p1=Person()
@@ -83,35 +88,40 @@ print(name)
8388
#Result:python 3.7
8489
```
8590

91+
Output:
92+
```
93+
python
94+
python 3.7
95+
```
8696

8797

8898
## Methods
89-
- A function inside a class is called method.
90-
- Method are accessible within the class.
91-
- Methods can accepts n number of parameter and return value using return keyword.
99+
- A function inside a class is called a method.
100+
- The method is accessible within the class.
101+
- Methods can accept n number of parameters and return value using the return keyword.
92102

93103
### How to define method?
94-
- **def** keyword is used to define method.
95-
- First parameter of method is **self**.
96-
- In method attributes are called with Classname dot(.)notation
104+
- **def** keyword is used to define the method.
105+
- The first parameter of the method is **self**.
106+
- In the method, attributes are called with Classname dot(.)notation
97107

98108
Syntax:
99109
```python
100110
Class <ClassName>:
101-
def MethodName(self,Paramter1,paramter2):
102-
#Code inside a method
111+
def MethodName(self,Paramter1,paramter2):
112+
#Code inside a method
103113
```
104114

105115
Example:
106116
```python
107117
#initialize the class
108118
class Person:
109-
#initialize the Method
110-
def Display(self):
111-
print(Person.name)
119+
#initialize the Method
120+
def Display(self):
121+
print(Person.name)
112122
```
113123

114-
### How to call method from a class using object?
124+
### How to call a method from a class using an object?
115125

116126
- to call a method from a class using class object we use dot(**.**) Notation
117127

@@ -126,13 +136,17 @@ Example:
126136
class Person:
127137
#initialize the methods
128138
def Display(self):
129-
print("simple output from Display method")
139+
print("the simple output from the Display method")
130140

131141
#initialize the class objects
132142
p1=Person()
133143

134144
#call Display method from Person class using p1 class object
135145
p1.Display()
136146

137-
#Result:simple output from Display method
147+
#Result: the simple output from the Display method
148+
```
149+
Output:
150+
```
151+
the simple output from the Display method
138152
```

0 commit comments

Comments
 (0)