Monday, November 2, 2020

, ,

Example Program for vars() function in python - Python Example Program

 vars() function in python return the dictionary attribute of an object.

Example Program for vars function in python
Example Program for vars() function in python

 

  • vars() can just take one object that can be module, class, instance, or any object which  having the __dict__ attribute in python program.
  • If the any object passed to vars() function doesn't  have the __dict__ attribute then it give an TypeError exception.
  • If any argument doesn't pass to vars() function then it act like an locals() function.

Example Program For vars function in python : -


class Foo:
  def __init__(self, a = 5, b = 10):
    self.a = a
    self.b = b
  
object = Foo()
print(vars(object))

OUTPUT

{'a': 5, 'b': 10}

0 comments:

Post a Comment