diff --git a/Lambda.py b/Lambda.py new file mode 100644 index 0000000..48dda8a --- /dev/null +++ b/Lambda.py @@ -0,0 +1,36 @@ +# this program shows the usage of the lambda function in python +# the lambda function refers to any anonymous function + +# syntax : +# lambda arguments : expression + +# wwhen to use lambda function :::: when u need an anonymous function for a short period of time or when u ned to pass an function as a argument to another function + + +add = lambda a,b,c,d : a + b + c + d + +print(add(1,2,3,4)) + +sub = lambda a,b : a - b + +print(sub(10,11)) + +def myfunc(x): + return lambda n: n*x + +y = myfunc(20) +print(y(2)) + +say_hello = lambda : print("hello") + +say_hello() + + +my_list = [1,2,3,4,5,6,7,8,9,10] + +new_list = list(filter(lambda x: x%2==0,my_list)) # the filter function takes two arguments one function and another list + + +print(new_list) + + diff --git a/classes_objects.py b/classes_objects.py new file mode 100644 index 0000000..c886366 --- /dev/null +++ b/classes_objects.py @@ -0,0 +1,23 @@ +#this program is an implementation of the classes and objects in python + +# classes serve as an blueprint for making objects in an code +# everything in OOP is regarded as an object +# the properies defined in the class are called attributes and the functions are called methods + + +class Human: + def __init__(self,name,age,gender): + self.name = name + self.age = age + self.gender = gender + + def My_classFunc(self): + print("Hello I am " + self.name) + +Human1 = Human("David",32,"male") + +print(Human1.name) +print(Human1.age) +print(Human1.gender) +Human1.My_classFunc() + diff --git a/function.py b/function.py index 9845e94..3f651f4 100755 --- a/function.py +++ b/function.py @@ -4,8 +4,6 @@ def __main__(): print("This is the first function of mine") print("we are in main !! ") -__main__() - def math(): x = int(input("enter your first number: ")) y = int(input("enter your second number:")) @@ -14,6 +12,7 @@ def math(): print("quotient = ",x/y) print("difference = ",x-y) +__main__() math() diff --git a/recurse.py b/recurse.py new file mode 100644 index 0000000..af6ef17 --- /dev/null +++ b/recurse.py @@ -0,0 +1,11 @@ +# program depicting the use of recursion in python + +def my_recursion(n): + if n == 1: + return 1 + else: + return (n * my_recursion(n-1)) + +x = my_recursion(900) +print(x) + diff --git a/while.py b/while.py index e4644a4..58bcc8d 100644 --- a/while.py +++ b/while.py @@ -6,8 +6,12 @@ } i = 0 while i<10 : - print(mydict) i += 1 + if i ==3 : + continue + + print(mydict) + \ No newline at end of file