Peter J. Holzer a écrit : > That's why it's called a container. But it also says *what* an object > must contain to be called a container. You could say that an int object > contains an integer value and a str object contains a reference to a > buffer containing the string - but those aren't references to other > objects, so int and str are not containers.
This is not how I interpret the wording : a string is a container for containing a reference to the characters the string holds. Depends on what you mean by "reference" and "contain". With the definition given, I cannot decide if a string or a range object is a container or not. For instance, can we say that range(100) contains 42 ? PLR document *states* that tuples, lists, sets are containers but doesn't mention if a string is a container or not. Nevertheless, str has a __contains__ method so if a string is not a container what is the logic ? > > You said that LR is designed to be much more formally defined, and > > favors correctness and completeness. Good, so can you answer this > > question after reading the LR : what is a "token"? Did't find a > > definition. > There is an indirect definition right at the start of chapter 3: "Input > to the parser is a stream of tokens, generated by the lexical analyzer." > So a token is what the unit of output of the lexer. This is the > definition. The rest of the chapter defines the details. As you know, the devil is in the details ;) A bunch of properties doesn't make a definition. What do we need is a characteristic property (necessary and sufficient). > > Is the "is not" operator a token? > Yes. See chapter 2.3.1. > 2.3.1 is about keywords : https://docs.python.org/3/reference/lexical_analysis.html#keywords not tokens (keywords are tokens but this is not the problem here). From 2.1.5 (Python 3.9 LR) ............... A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals (i.e., tokens other than string literals cannot be split across physical lines using a backslash). A backslash is illegal elsewhere on a line outside a string literal. ............... Giving the above, if "is not" were a token as you are explaining, the following code should be invalid syntax : # ------------ begin code ------------- 42 is\ not [42] # ------------ end code ------------- but this code compiles perfectly (there is a whitespace at the beginning of the second physical line). -- https://mail.python.org/mailman/listinfo/python-list