-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay17.py
More file actions
59 lines (37 loc) · 1.6 KB
/
Copy pathDay17.py
File metadata and controls
59 lines (37 loc) · 1.6 KB
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
54
55
56
57
58
59
# keyword arguments = arguments preceded by an identifier when we pass them to a function
# The order of the arguments doesn't matter, unlike positional arguments
# Python knows the names of the arguments that our function receives
def hello(first, middle, last):
print("Hello " + first + " " + middle + " " + last)
hello("J S ", "Prawin", "Kumar")
hello(last="J S ", middle="Kumar", first="Prawin") # keyword argument
# nested function calls = function calls inside other function calls
# innermost function calls are resolved first
# returned value is used as argument for the next outer function
num = (input("Enter a number: "))
num = float(num)
num = abs(num)
num = round(num)
print(num)
# the above code can be expressed in terms of nested function
print(round(abs(float(input("Enter a number :")))))
# variable scope = The region that a variable is recognized
# A variable is only available from inside the region it is created.
# A global and locally scoped versions of a variable can be created
name = "PrawinKumar" # global scope (available inside & outside functions)
def display_name():
# name = "Prawin" # local scope (available only inside this function)
print(name)
display_name()
print(name)
def display_name():
name = "Prawin" # local scope (available only inside this function)
print(name)
display_name()
"""
python follows the rule
L = Local
E = Enclosing
G = Global
B = Built-in
"""