payment by upi: sinhamit@icici or payment by bank account name: amit kumar sinha, account number: 2646728782 IFSC code: KKBK0005660 SWIFT: KKBKINBB

Please support if you like my work by payment through upi: sinhamit@icici or payment by bank

account name: Amit Kumar Sinha,
account number: 2646728782
IFSC code: KKBK0005660
SWIFT: KKBKINBB


Help Function   in Category: Python   by amit

🕙 Posted on 2023-06-24 at 14:22:29     Read in Hindi ...


Getting Help

    There are different ways in which you can get help from PYTHON CONSOLE (that is, >>> interactive shell) or even writing codes in your file with .py extension. Let's see how this can be done. Open your VSCode Editor, and type the following command in new.py file within your PROJECT FOLDER (after deleting or removing all codes previously written in it). You can also create a new file, for example, 001.py, 002.py, etc. and run/execute respective file from Command Shell or VSCode Terminal, as explained in previous page.

print( dir(list) )     # dir() is a built-in function, which shows all available methods for a class or function. It returns list of the attributes and methods of any object (say functions , modules, strings, lists, dictionaries etc.) Returns: dir() tries to return a valid list of attributes of the object it is called upon. This statement displays the following methods available for list class/function in python.

    You can see that there are some constructor methods, starting and ending with two underscore symbols. However, in practice, methods (without prefixed and post-fixed by two underscores) are used in Python programming, for example, 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'.

PS C:\xampp\htdocs> cd .\python2023\
PS C:\xampp\htdocs\python2023> py new.py
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

print( dir() )     # This statement displays the following OUTPUT:

PS C:\xampp\htdocs> cd .\python2023\
PS C:\xampp\htdocs\python2023> py new.py
['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']

print( help(dir()) )     # This statement displays the OUTPUT in context, that is dir() is treated as list, and thus, outputs the result of help( dir(list) ) or help( list() ) described below.

print( help(dir) )     # You should use keywords without parentheses within help() function, or help> CLI inside the PYTHON CONSOLE (that is, >>> interactive shell) to know more about dir, exit, etc. built-in functions.

C:\Users\yourName>python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 3.10's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the internet at https://docs.python.org/3.10/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> dir
Help on built-in function dir in module builtins:

dir(...)
    dir([object]) -> list of strings

    If called without an argument, return the names in the current scope.
    Else, return an alphabetized list of names comprising (some of) the attributes
    of the given object, and of attributes reachable from it.
    If the object supplies a method named __dir__, it will be used; otherwise
    the default dir() logic is used and returns:
        for a module object: the module's attributes.
        for a class object: its attributes, and recursively the attributes
            of its bases.
        for any other object: its attributes, its class's attributes, and
            recursively the attributes of its class's base classes.

print( help() )     # this statement will open the help> CLI, when you execute the py new.py file from the COMMAND LINE CONSOLE. If you are confused, or don't know what to do, press Enter or Return key twice or thrice, and you will exit from the help> CLI. To exit from the Python Console, that is, >>> you have to type exit() or quit() function and press Enter or Return key.

print( help(list) )     # this statement will OUTPUT following result.

C:\Users\yourName>python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 3.10's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the internet at https://docs.python.org/3.10/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> list
Help on class list in module builtins:

class list(object)
  |   list(iterable=(), /)
  |
  |   Built-in mutable sequence.
  |
  |   If no argument is given, the constructor creates a new empty list.
  |   The argument must be an iterable if specified.
  |
  |   Methods defined here:
  |
  |   __add__(self, value, /)
  |       Return self+value.
  |
  |   __contains__(self, key, /)
  |       Return key in self.
  |
  |   __delitem__(self, key, /)
  |       Delete self[key].
  |
  |   __eq__(self, value, /)
  |       Return self==value.
  |
  |   __ge__(self, value, /)
  |       Return self>=value.
  |
  |   __getattribute__(self, name, /)
  |       Return getattr(self, name).
  |
  |   __getitem__(...)
  |       x.__getitem__(y) <==> x[y]
  |
  |   __gt__(self, value, /)
  |       Return self>value.
  |
  |   __iadd__(self, value, /)
  |       Implement self+=value.
  |
  |   __imul__(self, value, /)
  |       Implement self*=value.
  |
  |   __init__(self, /, *args, **kwargs)
  |       Initialize self. See help(type(self)) for accurate signature.
  |
  |   __iter__(self, /)
  |       Implement iter(self).
  |
  |   __le__(self, value, /)
  |       Return self<=value.
  |
  |   __len__(self, /)
  |       Return len(self).
  |
  |   __lt__(self, value, /)
  |       Return self<value.
  |
  |   __mul__(self, value, /)
  |       Return self*value.
  |
  |   __ne__(self, value, /)
  |       Return self!=value.
  |
  |   __repr__(self, /)
  |       Return repr(self).
  |
  |   __reversed__(self, /)
  |       Return a reverse iterator over the list.
  |
  |   __rmul__(self, value, /)
  |       Return value*self.
  |
  |   __setitem__(self, key, value, /)
  |       Set self[key] to value.
  |
  |   __sizeof__(self, /)
  |       Return the size of the list in memory, in bytes.
  |
  |   append(self, object, /)
  |       Append object to the end of the list.
  |
  |   clear(self, /)
  |       Remove all items from list.
  |
  |   copy(self, /)
  |       Return a shallow copy of the list.
  |
  |   count(self, value, /)
  |       Return number of occurrences of value.
  |
  |   extend(self, iterable, /)
  |       Extend list by appending elements from the iterable.
  |
  |   index(self, value, start=0, stop=9223372036854775807, /)
  |       Return first index of value.
  |
  |       Raises ValueError if the value is not present.
  |
  |   insert(self, index, object, /)
  |       Insert object before index.
  |
  |   pop(self, index=-1, /)
  |       Remove and return item at index (default last).
  |
  |       Raises IndexError if list is empty or index is out of range.
  |
  |   remove(self, value, /)
  |       Remove first occurrence of value.
  |
  |       Raises ValueError if the value is not present.
  |
  |   reverse(self, /)
  |       Reverse *IN PLACE*.
  |
  |   sort(self, /, *, key=None, reverse=False)
  |       Sort the list in ascending order and return None.
  |
  |       The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
  |       order of two equal elements is maintained).
  |
  |       If a key function is given, apply it once to each list item and sort them,
  |       ascending or descending, according to their function values.
  |
  |       The reverse flag can be set to sort in descending order.
  |
  |   ----------------------------------------------------------------------
  |   Class methods defined here:
  |
  |   __class_getitem__(...) from builtins.type
  |       See PEP 585
  |
  |   ----------------------------------------------------------------------
  |   Static methods defined here:
  |
  |   __new__(*args, **kwargs) from builtins.type
  |       Create and return a new object. See help(type) for accurate signature.
  |
  |   ----------------------------------------------------------------------
  |   Data and other attributes defined here:
  |
  |   __hash__ = None

print( help(dir(list)) )     # This statement will output the result same as above, but of Help on list object:

    In next pages, you will learn about built-in functions, their methods and how to apply them in real-world programs.


Leave a Comment: