Jun-15-2022, 04:44 AM
I want to pass string functions like string.upper into another function as a parameter, there to be called as a function.
A simplified example:
A simplified example:
def transform_nth(str_in, n, transform): return ''.join([str_in[:n], str_in[n].transform(), str_in[n + 1:]]) name = transform_nth("dave", 2, String.upper) print(name)
Error:Traceback (most recent call last):
File "C:/Users/Documents/python/aaa.py", line 22, in <module>
name = transform_nth("dave", 2, String.upper)
NameError: name 'String' is not defined