Sunday, 2 April 2017

functions in python: predefined functions

Functions:

  • Function is a syntax or structure is used to represent the business logic to perform the operations.
  • The logic which is represented in function will be executed whenever we call a function.
  • We can call a function for any number of  times.
  • A function is a block of organized, reusable code that is used to perform a related action. 
  • Functions provide better modularity for your application and a high degree of code reusing.


Functions are categorized into two categories they are
  • Built in functions
  • User defined functions

Built in functions

  • The Python interpreter has a number of functions built into it that are always available. 
  • They are listed here in alphabetical order.
  • Built in functions information we can find out by using python manual.
  • Along with the python installation python manual also will come
Click on Python manual


Expand Python Standard Library


Click on Built-in functions


Examples:

   abs(x)

Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.
>>> abs(5)
5
>>> abs(-5)
5
>>> abs(5.0)

5.0

bin(x)
Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
>>> bin(2)
'0b10'
>>> bin(5)

'0b101'
       
help([object])

Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

>>> help( )

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/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> abs
Help on built-in function abs in module builtins:

abs(x, /)
    Return the absolute value of the argument.


help> 





No comments:

Post a Comment