Reputation: 21
Is there any way to call a function before its definition.
def Insert(value):
"""place value at an available leaf, then bubble up from there"""
heap.append(value)
BubbleUp(len(heap) - 1)
def BubbleUp(position):
print 'something'
This code shows "unresolved reference BubbleUp"
Upvotes: 1
Views: 3406
Reputation:
The code here doesn't show anything, least of all an error, because neither of the functions is called. What matters is the location of the call to Insert
, and as long as it comes after BubbleUp
(and why wouldn't it), there is no issue. Function definitions don't execute the function body, so you can define functions in whatever order you like, as long as you refrain from calling any of them until all necessary functions are defined.
Upvotes: 6