You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2019-09-19-Python-Oop.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ tags:
16
16
As we all know Python is Object Oriented Programming language. But you won't believe we are using Python OOP from our first program itself. For example if you try following snippet you will get what I am saying.
17
17
18
18
<preclass="line-numbers">
19
-
<codeclass="python">
19
+
<codeclass="language-python">
20
20
x = 2
21
21
print(type(x))
22
22
</code>
@@ -32,15 +32,15 @@ It will give you following result: ```<class 'int'>```
32
32
## How do we create simple class?
33
33
Using class keyword we can create new class. The syntax of class is given below:
34
34
<preclass="line-numbers">
35
-
<codeclass="python">
35
+
<codeclass="language-python">
36
36
class class_name:
37
37
method_definitions
38
38
</code>
39
39
</pre>
40
40
41
41
Let us create our own class,
42
42
<preclass="line-numbers">
43
-
<codeclass="python">
43
+
<codeclass="language-python">
44
44
class Employee:
45
45
pass
46
46
</code>
@@ -50,15 +50,15 @@ class Employee:
50
50
51
51
Let us create a new objects of our class Employee:
52
52
<preclass="line-numbers">
53
-
<codeclass="python">
53
+
<codeclass="language-python">
54
54
employee1 = Employee()
55
55
employee2 = Employee()
56
56
</code>
57
57
</pre>
58
58
59
59
Let us check whether we are created instances of class Employee successfully:
60
60
<preclass="line-numbers">
61
-
<codeclass="python">
61
+
<codeclass="language-python">
62
62
print(type(employee1))
63
63
</code>
64
64
</pre>
@@ -68,7 +68,7 @@ This will give you something like ```<class '__main__.Employee'>```. Then it is
68
68
Now it is the time to create instance variables. Instance variables are used for attach data to individual objects. Using these instance variable we can attach data field directly to at runtime. Instances are written outside class.
0 commit comments