Skip to content

Commit 080779a

Browse files
committed
Added namespace, dunder examples
1 parent d471c4a commit 080779a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def exploring():
2+
"""
3+
This function is created for exploring dunder variables
4+
"""
5+
print(f"Name of this function is {exploring.__name__}")
6+
print(f"And its documentation is {exploring.__doc__}")
7+
8+
print(f'globals: ', globals())
9+
exploring()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
course = 'python'
2+
3+
def change_local():
4+
"""
5+
This method will change the local value
6+
"""
7+
course = 'django'
8+
print('locals: ',locals())
9+
10+
def print_globals():
11+
"""
12+
This method is used to print globas
13+
"""
14+
print('globals: ',globals())
15+
16+
change_local()
17+
print_globals()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def sum(*items):
2+
"""
3+
This function calculates sum of items
4+
"""
5+
print('using our sum method')
6+
result = 0
7+
for item in items:
8+
result += item
9+
return result
10+
11+
result = sum(1,2,3,4,5)
12+
print(result)
13+
# This statement deletes the function from current namespace
14+
# so that built can be used
15+
del sum
16+
# We want to use built in method
17+
result = sum([1,2,3,4,5,6])
18+
print(result)
19+

0 commit comments

Comments
 (0)