Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconData Science USbreadcumb forward arrow iconPython In-Built Function in Python [With Syntax and Examples]

Python In-Built Function in Python [With Syntax and Examples]

Last updated:
28th Sep, 2022
Views
Read Time
5 Mins
share image icon
In this article
Chevron in toc
View All
Python In-Built Function in Python [With Syntax and Examples]

Built-in functions in Python are the functions that come pre-defined. Just a line of code can trigger these functions, and the programmer needs to pass relevant parameters to get the output from these functions. Python allows programmers to create custom functions and provides many in-built functions that can be used to make scripting faster and more optimized.

Since these functions are in-built and pre-coded, they follow a specific syntax that must be kept in mind while working with them. The table below lists all the built-in functions available in Python.

This article will talk about 8 of these in-built functions that you must know how to work with. Please refer to the official guide if you wish to dive deeper into other functions.

Important Python In-Built Functions to Know

Let’s look at some critical in-built functions available in the Python programming language:

Ads of upGrad blog

1. hash()

This method returns the hash value of the given object. Hash values can be understood as integers that can be used to compare dictionary keys during a lookup. The hash() method takes immutable objects as inputs and returns the respective hash values.

Syntax: hash(input_object)

Example: 

str = ”Hello World”

a = 13.8

tp = (‘a’, ‘b’, ‘c’)

print(“Hash for string:”, hash(str))

print(“Hash for float:”, hash(a))

print(“Hash for tuple:”, hash(tp))

Output:

hash value for a string:  5497742200142074869

hash value for a decimal:  1152921504606846988

hash value for a tuple:  -5693404743884429734

Check out our data science training to upskill yourself

Check our US - Data Science Programs

2. map()

The map() function allows programmers to execute specific functions for each item in an iterable. As a result, this function takes two inputs – both the required function and the iterable.

Syntax: map(function, iterable)

Example:

def square(n):

    return n*n

num = [1,2,3,4]

res = map(square, num)

print(“The result is: “ list(res))

Output:

The result is:  [1, 4, 9, 16]

As you can see from the output, the map() function mapped each iterable from the num list to the square function and gave the corresponding output.

3. zip()

The zip() method is used to map similar indices of passed iterators. The purpose of this is to take two separate iterators and use them in a single entity. So, if we pass two different iterations in a zip() method, where both iterators contain an equal number of elements, the zip() function returns the iterator of a tuple, where each tuple contains a map of the same index elements from the given iterators.

Syntax: zip(*iterators)

Example: 

num = [1,2,3]

letters = [‘one’, ‘two’, ‘three’]

res = zip(num, letters)

print (“The result is:” set(res))

Output:

The result is:  {(3, ‘Three’), (1, ‘One’), (2, ‘Two’)}

Read our Popular US - Data Science Articles

4. eval()

This function lets you evaluate Python expressions from compiled-code-based or string-based inputs. Simply put, the eval() method takes a string input, evaluates it as a python expression, and returns the output as an integer.

Syntax : eval(string)

Example: 

res1 = eval (‘10+15’)

res2 = eval(‘3*8’)

print(res1, res2)

Output:

25, 24

5. split()

The split() method comes in-built with the String modules in Python. This function splits a given string into smaller substrings based on various delimiters or separators. The function takes two parameters – separator and maxsplit. The value of separator is by default taken as whitespace, and that of maxsplit is -1.

Syntax: str.split(separator, maxsplit)

Example: 

str1 = “Welcome to upGrad”

str2 = “upGrad#for#Data#Science”

res1 = str1.split()

res2 = str2.split(“#”)

Output:

[‘Welcome’, ‘to’, ‘upGrad’]

[‘upGrad’, ‘for’, ‘Data’, ‘Science’]

6. ord()

This method returns the Unicode point of a given character. This function takes a character as input and returns integer numbers representing the input character’s Unicode point.

Syntax: ord(character)

Example: 

x = ord(‘a’)

y = ord(‘$)

z = ord(‘ ‘)

print (x, y, z)

Output:

97, 36, 32

7. dir()

This is a powerful in-built method available in Python that returns a list of all attributes of the specified object. It returns all the valid properties – including those properties that are built-in for default objects.

Syntax: dir(object)

Example: 

class Stud: 

    name = “Ron”

    age = 15

    rollNo = 32

print (dir(stud)

Output:

[‘__class__’, ‘__delattr__’, ‘__dict__’, ‘__dir__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__init_subclass__’, ‘__le__’, ‘__lt__’, ‘__module__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘__weakref__’, ‘age’, ‘name’, ‘rollNo’]

8. pow()

The pow() function takes two integers as inputs and raises the first integer to the power of the second integer. So, pow(x,y) will return x raised to the power of y as the output.

Syntax: pow(x,y)

Example: 

x = pow(2, 4)

y = pow(3, 2)

print(x, y)

Output:

16, 9

Ads of upGrad blog

Check out all trending Python tutorial concepts in 2024.

In Conclusion

In this article, we went over some key Python in-built functions. Thus, now you have a better idea of how to work around the syntax and invoke different in-built functions. However, since the world of Python is exceptionally vast, you must familiarise yourself with its myriad concepts, tools, functions, and libraries to master Python programming. We recommend exploring all Python in-built functions and experimenting with them in real-world programming.

Also, if you are looking for professional and expert support to guide you in this journey,  check out our Professional Certificate Program in Data Science and Business Analytics. The course is designed to help you start from the very basics and develop enough concepts to work on standalone projects and applications of Data Science.

Profile

Rohit Sharma

Blog Author
Rohit Sharma is the Program Director for the UpGrad-IIIT Bangalore, PG Diploma Data Analytics Program.
Get Free Consultation

Select Coursecaret down icon
Selectcaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Best Data Science Courses

Frequently Asked Questions (FAQs)

11. How many in-built functions are available in Python?

Python has all-in-all 68 in-built functions ready for use.

22. How to use in-built functions in Python?

To use in-built functions, you will need to know the syntax and the parameters it takes. Then, simply triggering the function using a one-line command will get the function activated, and you will get the desired output.

33. Are there only in-built functions in Python?

No, Python allows for both in-built and programmer-defined functions, as per your requirements.

Explore Free Courses

Suggested Blogs

Top 10 Real-Time SQL Project Ideas: For Beginners & Advanced
14857
Thanks to the big data revolution, the modern business world collects and analyzes millions of bytes of data every day. However, regardless of the bus
Read More

by Pavan Vadapalli

28 Aug 2023

Python Free Online Course with Certification [US 2024]
5519
Data Science is now considered to be the future of technology. With its rapid emergence and innovation, the career prospects of this course are increa
Read More

by Pavan Vadapalli

14 Apr 2023

13 Exciting Data Science Project Ideas & Topics for Beginners in US [2024]
5474
Data Science projects are great for practicing and inheriting new data analysis skills to stay ahead of the competition and gain valuable experience.
Read More

by Rohit Sharma

07 Apr 2023

4 Types of Data: Nominal, Ordinal, Discrete, Continuous
6060
Data refers to the collection of information that is gathered and translated for specific purposes. With over 2.5 quintillion data being produced ever
Read More

by Rohit Sharma

06 Apr 2023

Best Python Free Online Course with Certification You Should Check Out [2024]
5626
Data Science is now considered to be the future of technology. With its rapid emergence and innovation, the career prospects of this course are increa
Read More

by Rohit Sharma

05 Apr 2023

5 Types of Binary Tree in Data Structure Explained
5385
A binary tree is a non-linear tree data structure that contains each node with a maximum of 2 children. The binary name suggests the number 2, so any
Read More

by Rohit Sharma

03 Apr 2023

42 Exciting Python Project Ideas & Topics for Beginners [2024]
5854
Python is an interpreted, high-level, object-oriented programming language and is prominently ranked as one of the top 5 most famous programming langu
Read More

by Rohit Sharma

02 Apr 2023

5 Reasons Why Python Continues To Be The Top Programming Language
5339
Introduction Python is an all-purpose high-end scripting language for programmers, which is easy to understand and replicate. It has a massive base o
Read More

by Rohit Sharma

01 Apr 2023

Why Should One Start Python Coding in Today’s World?
5220
Python is the world’s most popular programming language, used by both professional engineer developers and non-designers. It is a highly demanded lang
Read More

by Rohit Sharma

16 Feb 2023

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon