Close Navigation
Learn more about IBKR accounts
Python Function Tutorial – Part II

Python Function Tutorial – Part II

Posted January 7, 2020
Jay Parmar
QuantInsti

See Part I of this installment to learn more about Python functions.

There are three types of Python functions:

  • Built-in Python functions such as print to print on the standard output device, type to check data type of an object, etc. These are the functions that Python provides to accomplish common tasks.
  • User-Defined Python functions: As the name suggests these are custom functions to help/resolve/achieve a particular task.
  • Anonymous Python functions, also known as lambda functions are custom-made without having any name identifier.

Built-in Python functions

Built-in functions are the ones provided by Python. We will go through a few of them now:

  • type(object) is used to check the data type of an object.
  • float([value]) returns a floating point number constructed from a number or string value.
  • int([value]) returns an integer object constructed from a float or string value, or return 0 if no arguments are given.
  • round(number[, ndigits]) is used to round a float number up to digits specified by ndigits.
  • abs(value) returns the absolute value of a value provided as an argument.
  • format(value[, format_spec]) converts a value to a ‘formatted’ representation, as controlled by format_spec.
  • str([object]) returns a string version of object. If the object is not provided, returns the empty string.
  • bool([value]) return a Boolean value, i.e. one of True or Falsevalue is converted using the standard truth testing procedure[1]. If the value is false or omitted, this returns False; otherwise, it returns True.
  • dir([object]) returns the list of names in the current local scope when an argument is not provided. With an argument, it attempts to return a list of valid attributes for that object.
  • len(object) returns the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

It is worth noting that almost all built-in Python functions take one or more arguments, perform the specific operation on it and return the output. We will keep learning about many more built-in Python functions as we progress through our Python learning journey. More information about various built-in functions can be obtained from Python official documentation

In the next installment, the author will discuss the user defined Python functions.

Visit https://www.quantinsti.com/ for ready-to-use Python functions as applied in trading and data analysis.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.