Python: Create a class and display the namespace of the said class
Python Class ( Basic ): Exercise-2 with Solution
Write a Python program to create a class and display the namespace of that class.
Sample Solution:
Python Code:
class py_solution:
def sub_sets(self, sset):
return self.subsetsRecur([], sorted(sset))
def subsetsRecur(self, current, sset):
if sset:
return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(current + [sset[0]], sset[1:])
return [current]
for name in py_solution.__dict__:
print(name)
Sample Output:
__module__ sub_sets subsetsRecur __dict__ __weakref__ __doc__
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to import built-in array module and display the namespace of the said module.
Next: Write a Python program to create an instance of a specified class and display the namespace of the said instance.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/class-exercises/python-class-basic-1-exercise-2.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics