0

In javascript, we have this object declaration:

var object = {property1:1,property2:1 }

In python, the traditional way we do that:

class my_cls:
  def __init__(self):
    self.property1=1
    self.property2=1
object = my_cls()

is there a shortcut in python to declare an object?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Are you looking for a dictionary which has a very similar syntax to the Javascript object? – Klaus D. Jun 24 '20 at 00:17
  • try [this](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python), [this](https://stackoverflow.com/questions/48285048/is-there-a-shorthand-initializer-in-python) and [this](https://stackoverflow.com/questions/2640806/javascript-like-object-in-python-standard-library) at least one of them should answer your question. – era-net Jun 24 '20 at 00:31

0 Answers0