您正在创建一个lambda(匿名)函数,它接受
s
作为参数,然后检查字符串“Price”是否在
s
或者你可以说
s
包含字符串“Price”。它会回来的
True
或
False
基于此。
此外,您正在将该函数存储在内部
string
变量。因此,您可以通过该变量调用该lambda函数:
string(s)
.
这里有一个例子(如果有帮助的话):
>>> # Create lambda function and store inside `string`
>>> string = lambda s: "Price" in s
>>> # Check `string` indeed a lambda function
>>> string
<function <lambda> at 0x7f4c0afa1630>
>>>
>>> # Call the lambda function with an argument
>>> # Inside lambda function, now, `s = "Hello, World"` !
>>> # It will check this: `"Price" in s`, it's not:
>>> string("Hello, World")
False
>>> # Now, `s = "What is the price of milk?"`
>>> # "Price" and "price" are not same !
>>> string("What is the price of milk?")
False
>>> string("Price of milk is $69.")
True
这个lambda函数与此相同:
def string(s):
return "Price" in s