Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Lambda.py
Original file line number Diff line number Diff line change
@@ -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)


23 changes: 23 additions & 0 deletions classes_objects.py
Original file line number Diff line number Diff line change
@@ -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()

3 changes: 1 addition & 2 deletions function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:"))
Expand All @@ -14,6 +12,7 @@ def math():
print("quotient = ",x/y)
print("difference = ",x-y)

__main__()

math()

11 changes: 11 additions & 0 deletions recurse.py
Original file line number Diff line number Diff line change
@@ -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)

6 changes: 5 additions & 1 deletion while.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
}
i = 0
while i<10 :
print(mydict)
i += 1
if i ==3 :
continue

print(mydict)