** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
l = ['Mon', 'tue', 'Wed', 'Thu', 'fri', 'sat', 'Sun']
def change_words(words, func):
for word in words:
print(func(word))
def sample_func(word):
return word.capitalize()
change_words(l, sample_func())
result
Mon
Tue
Wed
Thu
Fri
Sat
Sun
If you write it normally, it will look like this.
l = ['Mon', 'tue', 'Wed', 'Thu', 'fri', 'sat', 'Sun']
def change_words(words, func):
for word in words:
print(func(word))
change_words(l, lambda word: word.capitalize())
result
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Func used as an argument
lambda word: word.capitalize()
By writing, it can be described in the end.
Recommended Posts