Answers for "python class set dict method"

0

python class set dict method

class MyObject():
	
    def __init__(self):
      	self.a = 1
     	self.b = 2
      	self.c = 3
      
	def __iter__(self):
    	yield 'a', self.a
    	yield 'b', self.b
    	yield 'c', self.c

dict(MyObject())

>>>
{
  'a': 1,
  'b': 2,
  'c': 3
}
Posted by: Guest on July-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language