/ Python And R Data science skills: 05 what is class and how to create in python Telugu

Saturday 17 February 2018

05 what is class and how to create in python Telugu

05 Classes
In [1]:
class Employee:
    # Define an attribute called name
    name = "Ben"

    def changeName (self):
        # Change the value of the attribute within a method
        Employee.name = "Mark"

employee = Employee()
print(employee.name)
employee.changeName()
print(employee.name)
Ben
Mark
In [13]:
class Emp:
    name ="venkat"
    jobtitle="Sales person"
    sales=3
    def achive (self):
        if(self.sales>8):
            print("Achived")
        else:
            print("fail")
In [14]:
emp1=Emp()
In [5]:
emp1.name
Out[5]:
'venkat'
In [7]:
emp1.jobtitle
Out[7]:
'Sales person'
In [15]:
emp1.achive()
fail
In [16]:
dir(Emp)
Out[16]:
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 'achive',
 'jobtitle',
 'name',
 'sales']
In [18]:
type(Emp)
Out[18]:
type
In [19]:
type(emp1)
Out[19]:
__main__.Emp
In [20]:
l1=[1,2,3,4,5,]
In [21]:
l1
Out[21]:
[1, 2, 3, 4, 5]
In [22]:
type(l1)
Out[22]:
list
In [23]:
dir(l1)
Out[23]:
['__add__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__delitem__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__gt__',
 '__hash__',
 '__iadd__',
 '__imul__',
 '__init__',
 '__init_subclass__',
 '__iter__',
 '__le__',
 '__len__',
 '__lt__',
 '__mul__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__reversed__',
 '__rmul__',
 '__setattr__',
 '__setitem__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'append',
 'clear',
 'copy',
 'count',
 'extend',
 'index',
 'insert',
 'pop',
 'remove',
 'reverse',
 'sort']
In [25]:
l1.pop()
Out[25]:
5
In [26]:
l1
Out[26]:
[1, 2, 3, 4]

No comments:

Post a Comment