Objects:

In Python, everything is an object. we can use type() to check the type of object. We can create our own Object type using class keyword.

	
	print(type(1))		#	< class 'int' >
	
	print(type([]))	#	< class 'list' >
	
	print(type(()))		#	< class 'tuple' >
	
	print(type({}))	#	< class 'dict' >
	

Class:

Class object attributes


Methods

__init_ method :

self Parameter in Python :


Creating Instance Objects

To create instances of a class, we call the class using class name and pass the prameter as per its __init__ method.

		  
	# Creating Instance Object of Employee Class:
	
	employee1 = Employee("Sameer", 50000)
	employee2 = Employee("Rajeev", 9000)
	
	

Accessing Attributes:

We can access the object's attributes using the dot operator with object. Class variable can be accessed using class name directly.

		  
	# Creating Instance Object of Employee Class:
	
	employee1.empDetails()
	employee2.empDetails()
	
	print("Total Employee : {}".format(Employee.empCount))
	
	# Output :
	Name : Sameer , Salary : 50000
	Name : Rajeev , Salary : 9000
	Total Employee : 2
	
	

Methods to acces attributes :

		  
	getattr(employee1, 'name')		# Returns value of 'name' attribute
	hasattr(employee1, 'name')		# Returns true if 'name' attribute exists otherwise returns false
	setattr(employee1, 'name', "Raman") 		# Set attribute 'name' to Raman
	delattr(employee1, 'name')   			# Delete attribute 'name'
	

Add, remove, or modify attributes of classes and objects :

		  
	# Add
		employee1.empCode = 'JZADF123'
	# Modify 
		employee1.empCode = 'JUYDFDK1'
	# Delete 
		del employee1.empCode
			
	

Built-in Class Attributes :

		  
	print("Employee1.__bases__ : {}".format(Employee1.__bases__))		# Output: Employee1.__bases__ : ()
	print("Employee1.__dict__ : {}".format(Employee1.__dict__))		
	print("Employee1.__doc__ : {}".format(Employee1.__doc__)) 		# Output: Employee1.__doc__ : Employee base class, containing basic info. of employee
	print("Employee1.__module__ : {}".format(Employee1.__module__))   			Output: Employee1.__module__ : __main__
	print("Employee1.__name__ : {}".format(Employee1.__name__))					Employee1.__name__ : Employee
	

Special Methods :