Simpler way to create dictionary of separate variables?

前端 未结 27 2357
名媛妹妹
名媛妹妹 2020-11-22 02:42

I would like to be able to get the name of a variable as a string but I don\'t know if Python has that much introspection capabilities. Something like:

>&         


        
27条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 03:23

    >>> a = 1
    >>> b = 1
    >>> id(a)
    34120408
    >>> id(b)
    34120408
    >>> a is b
    True
    >>> id(a) == id(b)
    True
    

    this way get varname for a maybe 'a' or 'b'.

提交回复
热议问题