forked from amirkhan1092/computer-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
53 lines (32 loc) · 977 Bytes
/
Copy pathfunction.py
File metadata and controls
53 lines (32 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 1. Simple Function
def greet():
print("Hello, Welcome to Python!")
greet()
# 2. Function with Parameters
def add(a, b):
return a + b
print("Addition:", add(5, 3))
# 3. Function with Default Parameter
def introduce(name, age=18):
print(f"My name is {name} and I am {age} years old.")
introduce("Vanshika", 20)
introduce("Riya") # age default 18
# 4. Function with Return
def square(n):
return n * n
print("Square of 4:", square(4))
# 5. Function Returning Multiple Values
def calc(a, b):
return a+b, a-b, a*b
s, d, m = calc(10, 5)
print("Sum:", s, "Difference:", d, "Multiply:", m)
# 6. Variable Length Arguments (*args)
def total_sum(*numbers):
return sum(numbers)
print("Total Sum:", total_sum(1,2,3,4,5))
# 7. Keyword Arguments (**kwargs)
def student_info(**details):
for key, value in details.items():
print(f"{key} : {value}")
student_info(Name="Vanshika", Age=20, Course="Python")
# 8. Lambda Function (short fu