is defining a function first more efficient or is it better to def when is
about be used?(see example)
on (1) I define a function on the first line.
on (2) I define the same function on line 5.
which one is faster? is defining a function "closer" to when I need it
impractical for the complexity of larger programs(but does it make it
faster), or defining a function "far" from where I need it makes a larger
program slower when running(but also more practical).
I am using python. of course the difference here is probably in nano
seconds but this is just an example.
1-
def t(n1,n2):
v=n1-n2
return abs(v)
a = int(input('how old are you? \n'))
b = int(input('how old is your best friend? \n'))
c=t(a,b)
if a==b:
print ('you are both the same age')
else:
print('you are not the same age\nthe difference of years is %s
year(s)' % c)
input()
2-
a = int(input('how old are you? \n'))
b = int(input('how old is your best friend? \n'))
def t(n1,n2):
v=n1-n2
return abs(v)
c=t(a,b)
if a==b:
print ('you are both the same age')
else:
print('you are not the same age\nthe difference of years is %s
year(s)' % c)
input()
No comments:
Post a Comment