Write a python program to print properties and methods
Program
If you want to know the properties and methods of an object or module, use the dir() function. Below, we are checking for the properties and methods of a string object. You can also use dir() to check the properties and methods of modules. For instance, if you wanted to know the properties and methods of the collections module, you could import it and pass it as an argument to the function print(dir(collections)).
def myfun():
a = 'I love Python'
print(dir(a))
if __name__=="__main__":
myfun()
Output:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
More Questions
45 . Write a python program to print properties and methods
46 . Write a python program to open a website using python
47 . Write a python program to print most frequent letter in a string
48 . Write a python program to check memory sizes of list ,set ,tuple
49 . How do you confirm if an object is iterable using code?
50 . Write a python program to sort list with sorted & lambda
51 . Write a python program to access news using python
52 . Write a python program to print lowercase names
53 . Write a python program to Find Index Using Enumerate
54 . Write a python program to checking if a string is empty or not ?
55 . Write a python program to merge nested lists ?
For latest job updates join Telegram Channel: https://t.me/sateeshm