Type Conversions in Python:

Python for Data ScienceWe use type conversion functions in Python for Data Science to convert one data type to another directly. Below are some of the conversion functions.

  1. int(a,base) –  For converting all data types to integers. Base is there to specify the base of the string in case of strings as the data type.
  2. float() – Converts all data types to floating-point numbers or decimals.

data science

  1. ord() – there for conversion to an integer from character.
  2. hex() – This specific function converts to hexadecimal string from integer.
  3. oct() – This function is there for the conversion of integer to an octal string.

code in python for data science

  1. tuple() – It is there for conversion to tuple.
  2. set() – It is a function that returns the type after conversion of set.
  3. list() – It is a function that converts all data types into a list.

code in python for data science

  1. dict() – It is useful for the conversion of a tuple of order (key, value) to a dictionary.
  2. str() – Useful for the conversion of integer to a string.
  3. complex(real, imag) – for the conversion of real numbers to complex (real, imag) numbers.


To learn more about type conversion in python for data science, you can check this and this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.