Skip to content

Commit 3df4edc

Browse files
committed
Adding New Topic to Function
1 parent 7a9f390 commit 3df4edc

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

basics/Function/Arguments/agrs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
Arbitrary Arguments
3+
*args and **kwargs are special variables that allow you to pass any number of arguments to a function.
4+
5+
*args is a tuple and **kwargs is a dictionary.
6+
7+
syntax
8+
9+
def function_name(*args):
10+
statements
11+
12+
function_name(arguments)
13+
'''
14+
15+
def my_function(*args):
16+
for i in args:
17+
print(i)
18+
19+
my_function(1,2,3,4,5)
20+
21+
def my_function(**kwargs):
22+
for key, value in kwargs.items():
23+
print(f"{key}: {value}")
24+
25+
my_function(name="John", age=25)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
# Summation Program
3+
4+
**Create a Function** that will accept **N** number of integers as arguments it should get the sum of all integers passed in function and return its sum
5+
6+
**Print of Sum**
7+
8+
**Example**
9+
summation(1,2,3,4,5,6,7,8,9,10)
10+
11+
Output : 55
12+
'''
13+
14+
def summation(*N):
15+
sum = 0
16+
for i in N:
17+
sum += i
18+
return sum
19+
sum = summation(1,2,3,4,5,6,7,8,9,10)
20+
21+
print(sum)

basics/Function/Arguments/keywords.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Extension of Arguments
3+
'''
4+
5+
#Keyword
6+
def printFamily(firstNames,lastName):
7+
print(f"{firstNames} {lastName}")
8+
9+
printFamily("John","Doe")
10+
11+
# arbitrary with keyword
12+
def printFamily(*firstNames,lastName):
13+
for name in firstNames:
14+
print(f"{name} {lastName}")
15+
16+
printFamily("John","Jane","Jenny",lastName="Doe")

basics/Function/Arguments/kwargs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
kwargs is a special variable that allows you to pass keyword arguments to a function.
3+
4+
**kwargs is a dictionary.
5+
6+
Syntax
7+
8+
def function_name(**kwargs):
9+
statements
10+
11+
function_name(key1=value1, key2=value2)
12+
'''
13+
14+
15+
def printStudent(**student):
16+
print(f"Name : {student['name']}")
17+
print(f"Age : {student['age']}")
18+
19+
printStudent(name="John", age=25)

basics/Function/Arguments/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'''
2+
Re Learning Function w/ Parameter or Arguments
3+
'''
4+
5+
def sayHello(text):
6+
print(f"Hello {text}")
7+
8+
sayHello(input("Enter your name: "))

0 commit comments

Comments
 (0)