Functions

  • append()

  • len() - returns the length of a list

  • range()

  • int()

  • input()

  • sorted() - returns the sorted version of a list

def reverse_string(str):
    st1 = s[::-1]
    print(st1)
    
reverse_string("Hello")
def reverse_string(str):
    st1 = ''.join(reversed(s))
    print(st1)
    
reverse_string("Hello")

Higher-Order Functions

Functions Applied to Functions

Functions that operate on other functions are called Higher-Order functions

def mult_by_five(x):
    return 5 * x

def call(fn, arg):
    """Call fn on arg"""
    return fn(arg)

def squared_call(fn, arg):
    """Call fn on the result of calling fn on arg"""
    return fn(fn(arg))

print(
    call(mult_by_five, 1),
    squared_call(mult_by_five, 1), 
    sep='\n',
)

Last updated