My professor had mentioned that it's possible to pass functions like print as a parameter, but when I try and actually implement it I get a syntax error. Is it something small that I am missing here?
def goTime(sequence, action):
for element in sequence:
action(element)
def main():
print("Testing Begins")
test = list ( range( 0 , 20, 2) )
goTime(test, print)
print("Testing Complete")
Upon running the following, I receive this syntax error:
goTime(test, print)
^
SyntaxError: invalid syntax
If I define my own function that uses print, it works, like so:
def printy(element):
print(element)
def goTime(sequence, action):
for element in sequence:
action(element)
def main():
print("Testing Begins")
test = list ( range( 0 , 20, 2) )
goTime(test, printy)
print("Testing Complete")