On Sun, Jan 16, 2022 at 11:18 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Sun, Jan 16, 2022 at 09:18:40PM +1100, Chris Angelico wrote:
While it's tempting, it does create an awkward distinction.
f(1, 2, 3) # look up f, call it with parameters f[1, 2, 3] # look up f, subscript it with paramters f{1, 2, 3} # construct a frozenset
You forgot
f"1, 2, {x+1}" # eval some code and construct a string
Not to mention:
r(1, 2, 3) # look up r, call it with parameters r[1, 2, 3] # look up r, subscript it r"1, 2, 3" # a string literal
Strings behave differently in many many ways. Are there any non-string types that differ?
Reading this makes my eyes bleed:
>>> <1, 2, 3> < <1, 2, 3, 4> True
Fair point, but I can't imagine people comparing two literals like that. It's not quite as bad if you replace the left side with a variable or calculation, though it's still kinda weird.
Unfortunately there aren't many symbols available, and Python's kinda locked into a habit of using just one at each end (rather than, say, (<1, 2, 3>) or something), so choices are quite limited.
Triple quoted strings say hello :-)
See above, strings are different, and people treat them differently.
{{1, 2, 3}} would work, since that's currently a runtime error. But I prefer the f{} syntax.
Yeah, I think that ship has sailed. Double punctuation just isn't Python's thing, so there aren't really any good ways to shoehorn more data types into fewer symbols. ChrisA