Top 10 Python Built in Functions for Data Science

Top 10 Python Built in Functions for Data Science

6 mins read361 Views Comment
Vikram
Vikram Singh
Assistant Manager - Content
Updated on Oct 13, 2023 14:05 IST

Built-in functions are the pre-defined function in python. In this article, we will discuss different types of python built in functions with the help of examples.

2023_01_MicrosoftTeams-image-159.jpg

In Python, several functions and types are built into it that are always available to use. Built-in functions are the pre-defined function in Python that allows using the basic properties of string and numbers in your rules.
There are 60+ built-in functions in Python, but this article will discuss only the top 13 built-in functions mainly used in Data Science and Machine Learning.

Explore How to Find an Armstrong Number Using Python

Here is the list of all Python built-in functions.

abs() aiter() all() any()
next() ascii() bin() bool()
breakpoint() bytearray() bytes() callable()
chr() classmethod() compile() complex()
delattr() dict() dir() divmod()
enumerate() eval() exec() filter()
float() format() frozenset() getattr()
globals() hasattr() hash() help()
hex() id() input() int()
isinstance() issubclass() iter() len()
list() locals() map() max()
memoryview() min() next() object()
oct() open() ord() pow()
print() property() range() rep()
reversed() round() set() setattr()
slice() sorted() staticmethod() str()
sum() super() tuple() type()
vars() zip() _import_()

Now, let’s dive deep to see some of the built-in functions in detail.

1. abs()

  • It returns the absolute value of the number.
  • It takes only one argument.
    • The argument may be: an integer or floating point.
    • If the argument is complex: it will return the magnitude.
  • Example -1:
 
print("absolute value of -20 is:", abs(-9))
print("absolute value of 0 is:", abs(0))
print("absolute value of 9.38 is:", abs(9.38))
Copy code

Output

2. chr()

  • It returns the string representation of a character whose Unicode is an integer.
    • i.e., it takes Unicode as an input and returns the corresponding character as an output.
  • Example
 
# use chr() function to find the characters corresponding to the given Unicode
num = [65, 97, 36, 57]
for i in num:
print(chr(i))
Copy code

Output

2023_01_image-126.jpg

3. dict()

  • It is used to create the dictionary
    • Dictionaries are unordered collections of the object, that stores the data in key: value pair.
  • Example
 
D1 = {}
D2 = {'first_name' : 'Jim', 'age' : 23, 'height' : 6.0 }
D3 = dict(name='Jim', age=20, height = 6.1)
print("D1 is empty dictionary", D1)
print("creating 'dict' using curly braces and colons:", D2)
print("creating 'dict' using dict built-in function:", D3)
Copy code
What is Programming What is Python
What is Data Science What is Machine Learning

4. enumerate()

Enumerate in a built-in function of Python that helps you count each object of a list, tuple, set, or any data structure that can be iterated.

  • It takes input as a collection of tuples and returns it as an enumerate object.
  • An enumerated object (returned as an output) can be used directly for loops 
    • It can be converted as a list of tuples using the list method.
  • Example
 
car_list = [‘Honda’, ‘Tata’, ‘Mahindra’, ‘Ford’, ‘Toyota’]
e_car_list = enumerate(car_list)
print(list(e_car_list))
Copy code

Output

2023_01_image-129.jpg

Also Read: enumerate() function in Python

5. float()

The float () function in Python returns a floating-point number of a number or a string representation of a numeric value. 

  • a floating-point number.
  • If no value assigns, it will return 0.0.
  • If a string is passed without a number, it will return an error.

Example

 
print(float(2))
print(float('3.5'))
print(float())
print(float('inf'))
print(float('NaN'))
print(float('InfoEdge'))
Copy code

Output

2023_01_image-130.jpg

Also Read: Python float() function

6. len()

The len() function is one of the built-in functions in python that counts the number of items in an object (string, list, tuple, set, or sequence). It returns the number of objects in an integer format.

 
#find the length of the tuple
#define tuple
bike = ('yamaha', 'honda', 'tvs', 'RE')
len(bike)
Copy code

Output

2023_01_image-131.jpg

Also Read: len() function in Python

7. list()

The Python list object is the most general mutable sequence type provided by the language. Python lists are mutable that is the contents of the list be modified in place. Items in the list can be accessed, changed, new elements can be added, existing element can be removed or deleted.

Example:

 
# Changing List Items
List1 = ['Python', 2.0, 'Infoedge', 'Python Courses']
print("Original List:", List1)
List1[1] = 3.0
List1[-1] = 'Python Certifications'
print("Updated List:", List1)
Copy code

Output

2023_01_image-132.jpg

Also Read: Python list

Also Read: Python list practice problem for beginners

8. ord()

  • ord() function in Python converts a single Unicode character into its integer representation.
    • i.e., it takes a single character as an input and returns the corresponding Unicode. 
  • It is the opposite of chr() function.
  • Example
 
# use ord() function to find the Unicode of
UpperCase_Char =ord( 'A')
lowercase_char = ord('a')
Special_Char = ord('$')
num = ord('9')
print('The Unicodes are:', UpperCase_Char, lowercase_char, Special_Char, num)
Copy code

Output

2023_01_image-127.jpg

Must Read: ord() and chr() functions in Python

9. range()

The range function in Python returns a sequence of numbers starting from the given input value (by default: 0), increments the number at the defined step size (by default: 1), and stops before the specified value.

  • range () functions are most commonly used for loops to iterate sequences on a sequence of numbers.
  • range () function only takes integer values.

Example

 
#list the number of integers between 0 to 20 at the step size of 2
for i in range (0, 20, 2):
print(i, end =" ")
print()
Copy code

Output

2023_01_image-133.jpg

Also Read: Python range() function

Programming Online Courses and Certification Python Online Courses and Certifications
Data Science Online Courses and Certifications Machine Learning Online Courses and Certifications

10. set()

Python sets are unordered collections of unique elements and immutable objects. You can think of them as a dictionary with just the keys and its values thrown away. Therefore, each item of a set should be unique. Similar, to the dictionary, you can access, add, remove the element from the set.

Example

 
#create a set
set1 = set([2, 3, 4, 4, 5, 5, 6])
print("The set1 has:", set1)
set2 = {2, 2, 3, 4, 5, 5, 6, 6, 6, 7}
print("The set2 has:", set2)
Copy code

Output

2023_01_image-134.jpg

Also Read: Understanding Python Sets

Also Read: Python Set Practice Program for Begineer

11. str()

Any alphabet, numbers, characters you define within single or double quotes in Python becomes a python string. And the variable having a such value becomes a string variable. Python strings are “immutable” in nature, i.e. strings cannot be changed once they are created.

Example:

 
# string representation of an employee name
employee_name = str('Vikram')
print(employee_name)
# string representation of an employee code
employee_code = str(404)
print(employee_code)
# string representation of a numeric string 5.11 ft
height = str('5.11 ft')
print(height)
Copy code

Output

2023_01_image-135.jpg

Also Read: Getting Started with Python String

Also Read: Python String Practice Program for Begineers

12. tuple()

A tuple is a fixed-length, immutable sequence of arbitrary python objects. Syntactically, tuples (pronounced either as “toople” or “tuhple,”) are written as a series of objects which are separated by commas and coded in parentheses.

 
t = () # empty tuple
t1 = ('2') # An integer!
T1 = ('2,') # A tuple containing an integer
t2 = tuple('sequence')
t3 = ('peaches', 3.0+5j, [1, 22, 333])
print("t is of type", type(t))
print("t1 is of type", type(t1))
print("T1 is of type", type(T1))
print("t2 is", t2)
print("t3 is", t3)
Copy code

Output

2023_01_image-136.jpg

Also Read: Understanding Python Tuples

Also Read: Python Lists vs. Tuple

13. zip()

ip() function is a built-in function in PythonPython that takes any number of iterable (list, set, dictionary, tuples) as an argument and returns a single iterator object which is a tuple (zip object).

  • zip() function is used to iterate through multiple iterables.
  • The output tuple contains the elements from each passed iterable.

Example

 
# use zip() function with different number of iterable elements
# here the length of all three lists are different
cricketer = ['Dhoni', 'Virat', 'Rohit', 'Sachin', 'Ganguly']
age = [38, 34, 33, 45]
century = [25, 35]
zipped = zip(cricketer, age, century)
# print the list
list(zipped)
Copy code

Output

2023_01_image-137.jpg

Also Read: Python zip() function

Conclusion

Python has several pre-defined functions that is known as built-in function. In this article, we have discussed 13 built-in function in complete details with the help of examples.

Hope you will like the article.

Keep Learning!!

Keep Sharing!!

Top Trending Article

Top Online Python Compiler | How to Check if a Python String is Palindrome | Feature Selection Technique | Conditional Statement in Python | How to Find Armstrong Number in Python | Data Types in Python | How to Find Second Occurrence of Sub-String in Python String | For Loop in Python |Prime Number | Inheritance in Python | Validating Password using Python Regex | Python List |Market Basket Analysis in Python | Python Dictionary | Python While Loop | Python Split Function | Rock Paper Scissor Game in Python | Python String | How to Generate Random Number in Python | Python Program to Check Leap Year | Slicing in Python

Interview Questions

Data Science Interview Questions | Machine Learning Interview Questions | Statistics Interview Question | Coding Interview Questions | SQL Interview Questions | SQL Query Interview Questions | Data Engineering Interview Questions | Data Structure Interview Questions | Database Interview Questions | Data Modeling Interview Questions | Deep Learning Interview Questions |

FAQs

What are the top 10 built-in functions in Python for data science?

Built-in functions are the pre-defined function in Python that allows using the basic properties of string and numbers in your rules. There are 60+ built-in functions in Python. The top 10 built-in functions are abs, chr, dict, enumerate, float, len, list, ord, range, and set.

What is abs function in Python?

abs function takes only one argument and returns the absolute value of that number. The input argument can be float or int and if the input argument is complex, it will return only magnitude.

What is chr function in Python?

It returns the string representation of a character whose Unicode is an integer. i.e., it takes Unicode as an input and returns the corresponding character as an output.

What is dict function in Python?

It is used to create the dictionary. Dictionaries are unordered collections of object, that stores the data in a key: value pair.

About the Author
author-image
Vikram Singh
Assistant Manager - Content

Vikram has a Postgraduate degree in Applied Mathematics, with a keen interest in Data Science and Machine Learning. He has experience of 2+ years in content creation in Mathematics, Statistics, Data Science, and Mac... Read Full Bio