Skip to content

Commit 378dbdd

Browse files
authored
Removed Formatting errors
1 parent 78e31c3 commit 378dbdd

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

contrib/advanced-python/decorator-kwargs-args.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Functions in Python are so called first class objects, which means they can be t
66

77
```python
88
def func1():
9-
def func2():
10-
print("Printing from the inner function, func2")
11-
return func2
9+
def func2():
10+
print("Printing from the inner function, func2")
11+
return func2
1212

1313
```
1414
Assigning func1 to function_call object
@@ -17,7 +17,7 @@ function_call=func1()
1717
```
1818
Calling the function
1919
```python
20-
>> function_call()
20+
>>> function_call()
2121
```
2222
**Output**
2323
```
@@ -50,8 +50,8 @@ Now that you have understood why \* is used, we can take a look at *args. *args
5050
*args makes python functions flexible to handle dynamic arguments.
5151
```python
5252
def test1(*args):
53-
print(args)
54-
print(f"The number of elements in args = {len(args)}")
53+
print(args)
54+
print(f"The number of elements in args = {len(args)}")
5555
a=list(range(0,10))
5656
test1(*a)
5757
```
@@ -64,8 +64,8 @@ If in the test1 we do not use \* in the argument
6464

6565
```python
6666
def test1(*args):
67-
print(args)
68-
print(f"The number of elements in args = {len(args)}")
67+
print(args)
68+
print(f"The number of elements in args = {len(args)}")
6969
a=list(range(0,10))
7070
test1(a)
7171
```
@@ -78,8 +78,8 @@ The number of elements in args = 1
7878
**kwargs stands for keyword arguments. This is used for key and value pairs and similar to *args, this makes functions flexible enough to handle dynamic key value pairs in arguments.
7979
```python
8080
def test2(**kwargs):
81-
print(kwargs)
82-
print(f"The number of elements in kwargs = {len(kwargs)}")
81+
print(kwargs)
82+
print(f"The number of elements in kwargs = {len(kwargs)}")
8383
test2(a=1,b=2,c=3,d=4,e=5)
8484
```
8585
The above snippet uses some key-value pairs and out test2 function gives the following output:
@@ -96,18 +96,18 @@ Now that we understand what first class object, *args, **kwargs is, we can move
9696
```python
9797
import time
9898
def multiplication(a,b):
99-
start=time.time()
100-
c=a*b
101-
total=time.time()-start
102-
print("Time taken for execution of multiplication",total)
103-
return c
99+
start=time.time()
100+
c=a*b
101+
total=time.time()-start
102+
print("Time taken for execution of multiplication",total)
103+
return c
104104

105105
def addition(a,b):
106-
start=time.time()
107-
c=a+b
108-
total=time.time()-start
109-
print("Time taken for execution of addition ",total)
110-
return c
106+
start=time.time()
107+
c=a+b
108+
total=time.time()-start
109+
print("Time taken for execution of addition ",total)
110+
return c
111111

112112
multiplication(4,5)
113113
addition(4,5)

0 commit comments

Comments
 (0)