i
Python functionality and evolution
Installing Python (windows and Ubuntu)
IDLE (Integrated Development and Learning Environment)
Write the first python program and execute it
Keywords in Python
Identifiers in Python
Indentation in Python
Comments in Python
Multi-line Comments in Python
Getting user input
Python Function
Calling a function
Arguments in Function
Scope of Variables
Modules in Python
The PYTHON PATH-Variable
Python File Open
Python File Opening Modes
The file-Object-Attributes
Python File Close() Method
Python File Read/Write
Python File Position
Renaming and Deleting Files in Python
Python Directory Methods
File/Directory Methods
Exceptions in Python
The try-finally Clause
The argument of Exception
Raising Exceptions
Python Built-in Exceptions
Python OOPs Concepts
Python Classes/Objects
Creating Instance Objects
Accessing Attributes
Built-In Class Attributes
Garbage Collection
Python Inheritance
Overriding Methods
Method overriding
Data Hiding
Regular Expression
The match function
The search function
Match Object Methods & Description
Matching or Searching
Search or Replace
Regular Expression Modifiers / Option Flags
Grouping with Parentheses
Python Socket Programming
Python Socket Server
Python Socket Client
Send Data Between Clients
Python Socket or Server
Python Socket Clients
Points to ponder
You access object's attributes using dot operator with object. A class variable would be accessed using class name as follows:
emp1.displayEmp()
emp2.displayEmp()
print("Total Employee %d" % Emp.empcount)
Now, putting all concepts together −
"This create first object of Employee class"
emp1 = Emp("Zara",2000)
"This create second object of Employee class"
emp2 = Emp("Manni",5000)
emp1.displayEmp()
emp2.displayEmp()
print("Total Employee %d" % Emp.empcount)
Output:
Name : Zara,Salary: 2000
Name : Manni,Salary: 5000
Total Employee 2
You can add/remove/modify attributes of classes and objects at any time :
emp1.eage = 7 # Add an 'age' attribute.
emp1.eage = 8 # Modify 'age' attribute.
del emp1.eage # Delete age attribute.
Instead of using normal statements to access attributes we can use following functions:
The getattr(obj, name[, default])−to access attribute of object.
The hasattr(obj, name) − to check attribute exists or not.
The setattr(obj,name, value)−to set attribute. If attribute don’t exist, then it would be created.
The delattr(obj, name) − to delete attribute.
hasattr(emp1, 'eage') # Returns true if 'age' attribute exists
getattr(emp1, 'eage') # Returns value of 'age' attribute
setattr(emp1, 'eage', 8) # Set attribute 'age' at 8
delattr(empl, 'eage') # Delete attribute 'age'
Don't miss out!