diff --git a/special-method-names.html b/special-method-names.html index 94bdd89..3f6a11c 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -286,8 +286,8 @@ class FieldStorage: return len(self.keys()) ⑤
cgi.FieldStorage class, you can use the “in” operator to check whether a particular parameter was included in the query string.
-__contains__() method is the magic that makes this work.
-if 'q' in fs, Python looks for the __contains__() method on the fs object, which is defined in cgi.py. The value 'q' is passed into the __contains__() method as the key argument.
+__contains__() method is the magic that makes this work. When you say if 'q' in fs, Python looks for the __contains__() method on the fs object, which is defined in cgi.py. The value 'q' is passed into the __contains__() method as the key argument.
+any() function takes a generator expression and returns True if the generator spits out any items. The any() function is smart enough to stop as soon as the first match is found.
FieldStorage class also supports returning its length, so you can say len(fs) and it will call the __len__() method on the FieldStorage class to return the number of query parameters that it identified.
self.keys() method checks whether self.list is None, so the __len__ method doesn’t need to duplicate this error checking.