# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # بسم الله الرحمن الرحيم

class Human:
    pass


man = Human()

type(man)


class Human:
    def __init__(self):
        print('I am __init__')


man = Human()


class Human:
    def __init__(self, name):
        self.name = name


st_1 = Human('Ahmed')

st_2 = Human('Ali')

st_1.name

st_2.name

st_1.name = 'Mohammed'

st_1.name

st_2.name


class Human:
    score = 0 # class variable
    def __init__(self, name):
        self.name = name # instance variable


st_1 = Human('Ahmed')

st_2 = Human('Ali')

st_1.name

st_2.name

st_1.score

st_2.score

Human.score = 3

st_1.score

st_1.score = -20

st_1.score

st_2.score

Human.score

st_3 = Human('Mahmoud')

st_3.score


class Human:
    #self.score = 0
    def __init__(self, name, mobile):
        self.name = name
        self.mobile = mobile
        
    def __len__(self):
        pass


class Human:
    faults = 0 # class variable
    
    # instance method
    def __init__(self, name):
        self.name = name
    
    def speak(self):
        print(f'My name is: {self.name}')
    
    # Decorator - code that modifies behaviour of the following block
    @classmethod 
    def make_faults(omnia):
        omnia.faults += 1
        print(omnia.faults)


Human.make_faults()

st_1 = Human('Ali')

st_1.faults

Human.faults

st_1.make_faults()

Human.faults

st_1.faults


# ## OOP Concepts

class Human:
    no_faults = 0
    
    def __init__(self, name):
        self.name = name
        
    def speak(self):
        print(f'My name is: {self.name}')
        
    @staticmethod
    def make_faults(cls):
        cls.faults += 1
        
    def __len__(self):
        print('I am inside __len__function')
        print(f'Human Length is: 11')


a = Human('Ahmed')


class obj_1:
    def __init__(self):
        pass
    
    def __len__(self):
        print('I am obj1')
        return 0


class obj_2:
    def __init__(self):
        pass
    
    def __len__(self):
        print('I am obj2')
        return 0


o1 = obj_1()

o2 = obj_2()

a_list = [o1, o2]


# +
# for i in a_list:
#     print(type(i))
# -

def print_obj_length(a):
    for i in a:
        print(len(i))


print_obj_length(a_list)


class Human:
    no_faults = 0
    
    def __init__(self, name):
        self.name = name
        
    def speak(self):
        print(f'My name is: {self.name}')
        
    @staticmethod
    def make_faults(cls):
        cls.faults += 1
        
    def __len__(self):
        return len(self.name)
        
    def __add__(self, a):
        return self.name + a.name
    
    def __sub__(self, a):
        return 12
    
    def __mul__(self, a):
        return 13
    
    def __div__(self, a):
        return 14
    
    def __lt__(self, a):
        if self.name < a.name:
            return True
        return False
    
    def __contains__(self, a):
        return False


a = Human('Amer')
b = Human('Omnia')

'x' in a

a - b

len(a)

len(b)


# ## Inheritance

class Human:
    no_faults = 0
    
    def __init__(self, name):
        self.name = name
        
    def speak(self):
        print(f'My name is: {self.name}')
        
    @staticmethod
    def make_faults(cls):
        cls.faults += 1


class Employee(Human):
    def __init__(self):
        super(Employee, self).__init__('Ahmed')
        self.salary = 100


e = Employee()

e.name

e.salary


# +
# e.make_faults()
# -

class A:
    def p(self):
        print('inside class a')


class B:
    def p(self):
        print('inside class b')


class C(B,A):
    pass


obj = C()

obj.p()


class Human:
    def __init__(self, name):
        print('inside Human constructor')
        self.name = name


class Mammal:
    def __init__(self, age):
        print('inside Mammal constructor')
        self.age = age


class Employee(Human, Mammal):
    def __init__(self, name, age):
        Human.__init__(self, name)
        Mammal.__init__(self, age)


e = Employee('Amera', 20)

e.age

e.name


# +
def add(x,y):
    return x + y

def add(x,y,z):
    return x + y + z

add(1,2)


# -

def add(x,y,z):
    return x + y + z


add(1,2)



StarcoderdataJupyterScriptsDedupFiltered