Without that, if Python allowed it, would it do given:
a = "xxx"
test_dict = {a=3, b=2}
would it take test_dict to mean {"xxx":3, "b":2} or {"a":3, "b":2} ?JS does the latter always, so the variable a is not related to the literal key a which is understood as an unquoted string "a":
> a = "xxx"
'xxx'
> test_dict = {a:3, b:2}
{ a: 3, b: 2 }
> test_dict["xxx"]
undefined
> test_dict["a"]
3dict(1=5, 6=7, 7="aaa")
dict(hashableInstance="foo", anotherHashableInstance=23, (1,5)=8)
except Python syntax choices of course.
And if they wanted a string, they'd do it like:
dict("1"=5, 6=7, 7="aaa")
However, Python didn't even have sets at all until version 2.3, and they were in a stdlib module instead of being a built-in type until version 2.6. By that time dict notation was well entrenched.
User.objects.get_or_create(
username="bob",
defaults=dict(
email="bob@example.com",
)
this makes it easy to move fields between `defaults` and `kwargs`. Granted, you could achieve the same isomorphism with ** operator, but less readably IMO.For my part, those names are often the same anyway, though, since the calling scope names are often arbitrary and might as well match the parameter names.
{name, age}
does the same in modern JS, assigning the variable to the key with the same name.> x
set()
Well now I know! However I still think the shared usage of curly braces for dicts and sets could be somewhat confusing.
> x = {1, 2, 3}
> x
{1, 2, 3}
(But maybe no one should listen to me because I don't know how to do code blocks on HN.)
{*()}
but I guess it is equivalent to set()
I've noticed this in python in another place f"{var}"
is the same as str(var)
there was some other place I can't recall also noticing that (at least my perception understands that) Python is trying to kill my code golf tendencies.That said, it's probably just my own superstition and of course it doesn't remove my premature optimization tendencies...
Why the triple question marks? You could have just asked the question straight.