w3resource

Python: Create a class and display the namespace of the said class


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:

Flowchart: Create a class and display the namespace of the said class

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.



Follow us on Facebook and Twitter for latest update.