In javascript, say we have two local variables name
and age
, and we want to create an object literal (dictionary) in the form:
let person = {
name: name,
age: age
}
This assignment can be shortened to this statement with the same outcome:
let person = {
name,
age
}
Is there an equivalent shorthand for this in python? Or do dictionaries have to be written like this?
person = {
"name": name,
"age": age
}