Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
7 Things You Didn’t Know About Java
Next article icon

10 Python In-Built Functions You Should Know

Last Updated : 23 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Python is one of the most lucrative programming languages. According to research, there were approximately 10 million Python developers in 2020 worldwide and the count is increasing day by day. It provides ease in building a plethora of applications, web development processes, and a lot more. When it comes to making a program short and clear, we use in-built functions which are a set of statements collectively performing a task. Using in-built functions in a program makes it beneficial in many ways such as:

  • Makes it less complex.
  • Enhances readability.
  • Reduces coding time and debugging time.
  • Allows re-usage of code.

10-Python-In-Built-Functions-You-Should-Know

Hence, it plays a major role in the development of an application. In python 3, we have 68 in-built functions, some of them are listed below:

1) append()

This method adds an item at the end of the existing list, tuple, or any other set. Then, the length of the list gets increased by one. We can append an item to the list and also list to a list. It adds any data type which is to be added at the end of the list. It has time complexity: O(1).

Syntax: 

append(item) 

where item refers to the item needed to be appended with the existing element.

For Example:

a=[“apple”,” banana”,” mango”,” grapes”]

a.append(“orange”)

print(a)

Output:

[“apple”,” banana”,” mango”,” grapes”,” orange”]

2) reduce()

The reduce() function applies a function of two arguments collectively on a list of objects in succession from left to right to reduce it to one value. It is defined in a functools library. This works better than for loop. 

Syntax: 

reduce(function, iterable) 

where, function refers to the function which will be used in a program, and iterable refers to the value that will be iterated in the program. 

For Example:  

From functools import reduce

Def sum(a, b):

res=return (sum, [1,2,4,5])

print res

Output: 

12

3) slice()

This function returns the sliced object from a given set of elements. It allows you to access any set of sequences whether it is ta tuple, list, or set. Time complexity of slice() is O(n).

Syntax: 

slice(start, stop, step) 

where start refers to the start index from where you have to copy, stop refers to the index till where you want to slice, and step refers to the count by which you want to skip.

For Example:

a=”Hello World”

y=slice(2,4,1)

print(y)

Output:

 lo

4) sorted()

This function sorts the given element in specified (ascending or descending) order. The set of elements could be a list, tuple, and dictionary. The time complexity of the sorted function is O(n.logn).

Syntax: 

sorted(set of elements) 

where a set of elements refers to the elements which need to be sorted.

For Example:

a=[1,7,3,8]

y=sorted(a)

print(y)

Output: 

[1,3,7,8]

5) split()

This method breaks up the string into a list of substrings, based on the specified separator. It returns strings as a list. By default, whitespace is the separator. Time complexity of split() is O(n).

Syntax: 

split(separator)

where separator refers to the value which is to be split from the given sequence.

For Example: 

a="HelloWorld"

y=a.split('l')

print(y)

Output:

 ['He','oWor','d']

6) eval()

The eval() function evaluates the given expression whether it is a mathematical or logical expression. If a string is passed through it, it parses the function, compiles it to bytecode, and then returns the output. Since operators have no time complexity therefore eval doesn't have one. 

Syntax:

 eval(expression)

where the expression could be any operation such as mathematical or logical.

For Example: 

x=6

y=eval('x*8')

print(y)

Output:

 48

7) bin()

This function converts an integer to a binary string that has the prefix 0b. Also, the integer passed could be negative or positive. Its time complexity for a number n is O(log(n))

Syntax:

 bin(integer)

where the integer is any value passed to receive its binary form. 

For Example:

print(bin(8))

Output:  

0b1000

8) map()

This function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple, etc.). It applies a function to all objects in a list. The time of complexity of the map() function is O(n).

Syntax: 

map(function, iterable)

where function refers to the function which will be used in a program, iterable refers to the value that will be iterated in the program. 

For Example:

def add(x):

   return x+2

x = map(add, (3, 5, 7, 11, 13))

print (x)

Output:

(2,7,9,13,15)

9) filter()

This function creates a new iterator from an existing one (such as a list, tuple, or dictionary) that filters elements. It checks whether the given condition is available in the sequence or not and then prints the output. The time complexity of the filter function is O(n).

Syntax: 

filter(function, iterable)

where function refers to the function which will be used in a program, iterable refers to the value that will be iterated in the program. 

For Example:

c = ['Ant','Lizard','Mosquito','Snake']      

def vowels(x):

return x[0].lower() in 'aeiou'

items = filter(vowels, c)

print(list(items))

Output:

 ['Ant']

10) exec()

This function executes the given condition and prints the output in python expression. It executes the program dynamically Python exec() function executes the dynamically created program, which is either a string or a code object. If it is a string, then it is parsed as a Python statement and then executed; else, a syntax error occurs.

Syntax: 

exec(object[, globals[, locals]])

where the object can be a string or object code, globals can be a dictionary and the parameter is optional, and locals can be a mapping object and are also optional.

For Example:

exec(print(sum(2,8)))

Output:

10

So till now you must have got the information about 10 Python in-built functions. With these in-built functions, you can make complex applications very easy. Use it whenever you're working on any Python application to be handy. 


Next Article
7 Things You Didn’t Know About Java

I

ishasharma44
Improve
Article Tags :
  • GBlog

Similar Reads

  • Top 10 Python Applications in Real World
    We are living in a digital world that is completely driven by chunks of code. Every industry depends on software for its proper functioning be it healthcare, military, banking, research, and the list goes on. We have a huge list of programming languages that facilitate the software development proce
    6 min read
  • 7 Things You Didn’t Know About Java
    Undoubtedly, Java has been the most famous and widely used programming language out there. Not 1, or 2 but, today it covers almost every sector in the market. The reason is its adaptive nature and platform independence. By 2024, Java has already entered its 29th Anniversary and there’s no looking ba
    8 min read
  • 10 C++ Programming Tricks That You Should Know
    C++ Programming Language is a powerful, versatile, and compiled language, which means the source code is converted into machine language before the execution. In order to make your code as efficient and effective as possible, you should be aware of the following tricks and techniques. Hence, it's be
    10 min read
  • Top 10 Python Developer Skills That You Must Know in 2024
    The tech industry is a whirlwind of innovation, and Python stands tall as one of the most in-demand programming languages fueling this progress. According to a recent Stack Overflow survey, Python reigns supreme as the most preferred language among developers. This translates to a goldmine of opport
    8 min read
  • Top 20 Linux Applications You Must Use
    Linux is a free and open-source operating system based on the Linux kernel. It consists of a wide variety of essential applications that can be used to perform many day-to-day tasks. Multiple alternative applications of Linux are available to perform every task. So, it is a tedious job to select the
    11 min read
  • Top 10 Python Built-In Decorators That Optimize Python Code Significantly
    Python is a widely used high-level, general-purpose programming language. The language offers many benefits to developers, making it a popular choice for a wide range of applications including web development, backend development, machine learning applications, and all cutting-edge software technolo
    12 min read
  • 12 Reasons Why You Should Learn Python [2025]
    In the fast-paced world of technology, learning a versatile and in-demand programming language like Python can open doors to numerous opportunities. Python has established itself as a powerhouse in various domains, from web development and data analysis to artificial intelligence and automation. As
    8 min read
  • Top 20 Python Libraries To Know in 2025
    Python is a very versatile language, thanks to its huge set of libraries which makes it functional for many kinds of operations. Its versatile nature makes it a favorite among new as well as old developers. As we have reached the year 2025 Python language continues to evolve with new libraries and u
    10 min read
  • Top 10 Python Packages to Learn in 2024
    Python is one of the most popular programming languages which is used by more than 80% of the developers. Top Python packages offer some amazing features like easy to learn and understand, enhanced security and performance. It consists of modules, packages, and libraries that play a major role in ke
    6 min read
  • Top 10 JavaScript Fundamentals That Every Developer Should Know
    Javascript is an object-oriented language that is lightweight and used for web development, web applications, game development, etc. It enables dynamic interactivity on static web pages, which cannot be done with HTML, and CSS only. Javascript is so vast that even mid-level professionals find it dif
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences