w3resource

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:

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://198.211.115.131/python-exercises/class-exercises/python-class-basic-1-exercise-2.php