Repository navigation
Expand file tree
/
Copy path020_oop_classes.py
More file actions
70 lines (60 loc) · 2.1 KB
/
Copy path020_oop_classes.py
File metadata and controls
70 lines (60 loc) · 2.1 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
""" MARKDOWN
---
YamlDesc: CONTENT-ARTICLE
Title: python class and objects
MetaDescription: python class object oriented programming example code, tutorials
MetaKeywords: python, class, objects, object oriented programming, example code, tutorials
Author: Venkata Bhattaram / tinitiate.com
ContentName: oop-class-objects
---
MARKDOWN """
""" MARKDOWN
# PYTHON Object Oriented Programming
* Python supports, Object Oriented Programming, Its a concept where data and
functionality are combined into a unit called as CLASS.
* Class is a collection of DATA and FUNCTIONS that operate on that data
* Data could be Variables Lists, tuples, dictionaries..
* Functions are operations that perform operations on data values,
such as get squareroot or get square of a given data set.
* For more complex business scenarios, Data could be Credit and salary
information and the function could be approve/disapprove loan.
* Objects are instantiation of classes (reference of a class instance)
* While Class is a Spefcification, Object is the implementation
(or the executing instance of the class).
MARKDOWN """
# MARKDOWN ```
##################
# Create a CLASS #
##################
class Tinitiate:
'This is a brief note about the class, This is the TINITIATE Class'
# CLASS VARIABLES
# a class Variable
ti_var = 100
# a class list
ti_list = ["a","b","c"]
# a class tuple
ti_tuple = ("x","y","z")
# a class dictionary
ti_dictionary = {"1":"A", "2":"b", "3":"c"}
# CLASS FUNCTION
def ti_function(self):
"This is a class function"
print("This is a message from the TINITIATE Class ti_function")
#################
# Using a Class #
#################
# Create an object of the class
tinObject = Tinitiate()
# use the Class variables/lists..
print(tinObject.ti_var)
print(tinObject.ti_list)
print(tinObject.ti_tuple)
print(tinObject.ti_dictionary)
# Call the the class function
tinObject.ti_function() # This will print the message from the function
# Create another object of the class
tObject = Tinitiate()
# Call the the class function
tObject.ti_function()
# MARKDOWN ```