The Wayback Machine - https://web.archive.org/web/20241008213137/https://www.geeksforgeeks.org/10-python-in-built-functions-you-should-know/
Open In App

10 Python In-Built Functions You Should Know

Last Updated : 23 May, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 



Similar Reads

13 Things You Should Know Before You Enter In Web Development
Every beginner starts their journey in web development learning frontend part, backend part, and some tools which are important to build the web project. Building your first project on your own after so many struggles is an exciting feeling for the beginners. You start having a lot of expectations from your job but when you enter the industry you f
7 min read
10 Secret AI Websites You Should Know (But No One Told You About)
If you're looking around you, people now started using AI websites and apps. It's true that the AI era has started and boomed since the launch of ChatGPT. So, are you using AI to boost your performance? If not, how does it feel living under the rock? With so many great things on the table, we often miss out on the best ones. Well, that’s the same c
10 min read
How Much Python Should You know To Learn Django?
How much python is required to learn Django?? This question comes to the mind of every beginner and experienced developer who wants to learn Django and build an application in it. No doubt most developers or beginner wants to learn any framework or library as soon as possible. We all want to know the minimum prerequisite that is needed to learn any
6 min read
10 Things You Should Know As a Web Developer
Writing a thousand lines of code and turning that into a website is one of the most creative and complicated things for web developers. If you get excited seeing a lot of beautiful websites and thinking to try your hands on them then we need to open your eyes by telling you some important things that you should know as a web developer. Creating a w
8 min read
5 Operating System Concepts You Should Know As a Developer
Being a developer you might have focused your skills on problem-solving and data structure. Well, no doubt this is one of the most essential skills. Apart from that have you ever tried to know what else is more important? Consider a scenario that you're executing a code, but your program runs too slowly. You check your code, and you find that there
6 min read
Things You Should Know About React Hooks
React...We all know the importance of this library in the tech industry. Most of the applications are switching to React because of its advantages and features. There are many features of React. React hooks is one of them. React hooks was first released in October 2018. In React a lot of developers use the lifecycle method which is nothing, but jus
4 min read
Top 10 Mobile App Development Trends You Should Know
Undoubtedly, mobile apps have been impacting our lives daily. The mobile app development market has been spreading enormously. So, every person must be acquainted with the trends, including the modification in mobile app developments. Hanging around with the updates is the most challenging part of achievements. Since the time mobiles and smartphone
6 min read
5 Myths About Artificial Intelligence You Should Know
There have been significant changes brought about by the introduction of computers and technology. There are numerous technologies present today and among those Artificial Intelligence is probably the center of attention. For both good and bad reasons AI is today a hot topic. AI is a progressive step to technological advancements. Among the many be
6 min read
6 Common Cryptocurrency Scams You Should Know
The cryptocurrency industry has a worth of more than a billion-dollar. According to the analysis of MarketsandMarkets, the 2021 cryptocurrency market size is around 1.6 Billion Dollars which will exceed 2 billion by 2026. Such a growing market is attracting a lot of investors, entrepreneurs, and business owners too to invest in various cryptocurren
6 min read
7 Challenges in Test Automation You Should Know
Today, test automation has become a new trend in the tech industry when it comes to efficiency and quickness. Undoubtedly it helps in achieving milestones more quickly and on the other hand, also boosts productivity. In fact, most IT firms are now shifting towards automation and it’s good to take adopt new trends. But, as we all know, anything can
6 min read
7 Benefits of Microsoft Power BI You Should Know
In today’s data-driven world, the success of any business relies heavily on a huge amount of data. These data are highly important for the efficiency, growth, and success of a business or an organization. But monitoring, estimating, and analyzing these data, is something that needs to be constantly performed. In simple words, Business Intelligence
5 min read
10 Most Common SQL Queries That You Should Know
To handle huge amounts of data, companies rely on SQL which stands for Structured Query Language which is used to communicate with the database. It provides a path through which we can access the database without going through complicated procedures. All the operations you can do follows the CRUD acronym. CRUD stands for the four most important ope
5 min read
10 Mac OS Keyboard Shortcuts That You Should Know
Sometimes a small shortcut can be a life savior. Shortcuts improve efficiency and speed. There are multiple mac keyboard shortcuts which are effective and unique. Also, mac devices have very different builds and settings than Windows OS. Thus a new mac user can find it difficult to adapt to those changes. Here are the 10 mac keyboard shortcuts ever
3 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 better to know some C++ tricks and tips to reduce a
10 min read
10 Web Development and Web Design Facts That You Should Know
Web Development has grabbed a lot of attention in today's date. But the question arises, why has it gained such a massive audience in the last decade. So Here's the answer: Web development is the basic building and maintenance of websites; it’s the whole procedure that happens to make a website look great, responsive, work smooth, and performing we
6 min read
Top 10 Data Science Companies You Should Know in 2024
In today's digital world, businesses are constantly generating massive amounts of data. This is where data science companies come in – they help organizations organize and analyze this data to extract valuable insights. The field of data science is booming, with many top data science companies offering exciting job opportunities for skilled data sc
13 min read
Top 10 Java Frameworks You Should Know in 2024
In today's digital world, web applications play a crucial role across various industries. Building robust and scalable applications often requires choosing the right development tools. Among these tools, Java frameworks stand out for their efficiency and reliability, making them a popular choice for enterprise-level development. This article explor
8 min read
Top Selenium Frameworks You Should Know
As you must be well aware of the fact that test automation is a process of executing test cases by using certain automation tools. The reason behind introducing automation was to speed up the process and increase efficiency and that's what tools like Selenium are performing in the testing industry. Today Selenium has been one of the most essential
7 min read
15 Best CI/CD Tools That You Should Know
Continuous Integration and Continuous Delivery (CI/CD) is modern-day practices to continuously improve the software by adding new feature and for that we have to change the existing files and deploy them. Doing it manually every time may consume a lot of developer's time, so to make the process more simple and reliable developers use CI/CD tools th
11 min read
ExpressJS vs NestJS - 7 Differences That You Should Know
For building large-scale applications, people look for lightweight frameworks. For that reason, NestJS is taking command over ExpressJS. No doubt ExpressJS has gained popularity in the last few years among developers, NestJS is on the way and will pave the way to greater use in upcoming years. Now, when you don't know about ExpressJS and NestJS, no
8 min read
Kanban vs. Scrum : Top Differences You Should Know
In the world of Agile project management, there are two popular methodologies, Kanban and Scrum, have gained significant attention. Each offers unique approaches to organizing and executing tasks, serving different project requirements. To make informed decisions and adopt the most suitable method for their project it is important to understand the
5 min read
7 Things You Should Know Before Switching To Linux
If you are reading this blog, you are most probably using Windows or Mac and looking to switch over. Linux is an excellent alternative to Windows or Mac, but sometimes it can confuse you at first. Linux has grown so much in recent years that you can now install it without even using a terminal window. There are multiple Linux distributions, such as
6 min read
ChatGPT vs Google BARD - Top Differences That You Should Know
'Google BARD vs. Chat GPT' is currently the most talked-about topic, rather than focusing on who will win, let's examine how each of these topics excels in its niche and recognize that we don't need to pick a winner. Instead, we can use each of these topics as appropriate depending on the situation. Users have been trying to compare the two AIs aga
8 min read
GPT 4 vs GPT 3: Top Differences That You Should Know in 2024
The AI chatbot is completely changed by ChatGPT. It has seized the AI market and established a powerful foothold there. Now that the ChatGPT has figured things out, it is prepared to advance with new plans and advancements. A new version of ChatGPT was thus released. An artificial intelligence model called GPT-4 has begun to be released by OpenAI a
6 min read
Top 5 Skills You Must Know Before You Learn ReactJS
Do you know enough javascript before jumping into React??Do you know how to use the map() method to loop through an array in javascript or ReactJS?? If you are learning React and you get stuck on these kinds of above questions then definitely you are making mistakes in your learning process. There is no doubt that ReactJS is the most popular librar
8 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 technology, and is preferred for both beginners as well as
12 min read
15 Laws of UX That Every Designer Should Know
UX is a vast field, which people always align to “solely creativity” but there are some fixed principles. These principles are based on user behavior, expectation, and research carried over the years. The phrase "user experience" refers to all the interactions that people have with a product, including visual design, information architecture, usabi
10 min read
Top NoSQL Databases That Every Data Scientist Should Know About
The term NoSQL database refers to the non- relational database. Though there is confusion in the meaning of the term “NoSQL” some say that it stands for ‘non SQL’ while a majority of people say that it stands for ‘not only SQL’. But we know that NoSQL databases are those databases that store or keep the data in a certain format as compared to other
5 min read
8 Best Android Libraries That Every Android Developer Should Know
Android is an operating system which is built basically for Mobile phones. It is used for touchscreen mobile devices like smartphones and tablets. But nowadays these are utilized in Android Auto cars, TV, watches, camera, etc. Android has been one of the best-selling OS for smartphones. Android OS was developed by Android Inc. which Google bought i
5 min read
7 Principles of Meteor.js That Web Developer Should Know
Over the past two decades, the Internet has undergone significant development. But the majority of websites are created utilizing outdated methods. Meteor focuses on developing contemporary apps for today, not for the past. Meteor has created seven guiding principles to ensure that its focus remains true. These guidelines serve as a description of
6 min read
Article Tags :