CMP 316 WORD
DOCUMENT
BUILT-IN
FUNCTIONS
GROUP 1
GROUP MEMBERS:
1. MATHEW ESTHER
2. OMOSIGHO GODSWILL
3. UKACHI VICTOR
4. EFEDJIE VICTOR
5. ABUJANA JEREMIAH
6. JOSEPH CHIAGOZEIM
7. NWODO DAVID
TABLE OF CONTENT
1.1 WHAT ARE FUNCTIONS
1.2 WHAT ARE BUILT-IN FUNCTIONS
1.3 CATEGORIES OF BUILT-IN FUNCTIONS
1.4 APPLICATION OF BUILT-IN FUNCTION
1.5 CHARACTERISTICS OF BUILT-IN FUNCTIONS
1.6 ADVANTAGES OF BUILT-IN FUNCTIONS
1.7 LIMITATIONS OF BUILT-IN FUNCTIONS
1.8 CONCLUSION
1.1 WHAT ARE FUNCTIONS
A function is a block of reusable code designed to perform
a specific task. It usually takes input also known as arguments,
performs an operation, and returns an output. In Python
programming, a function is a block of reusable code designed to
perform a specific task. Functions allow developers to organize
code, improve readability, and reduce redundancy.
1.1 WHAT ARE BUILT-IN FUNCTIONS
Built-in functions in Python are pre-defined functions
provided by Python's standard library. They are readily available
for use without requiring any imports or additional setup,
making them convenient for performing common tasks. They
are predefined functions using the basic properties of string and
numbers in your rules. The built-in functions in Python have
evolved along with the language itself, reflecting Python's
design principles of simplicity, readability, and functionality.
1.2 CATEGORIES OF BUILT IN FUNCTION
1. Input and Output Functions
Python provides built-in functions for getting input from the
user and printing output to the console. These functions can be
used to interact with the user and display information to the
console. Some of the most commonly used input and output
functions in Python include:
input() – gets input from the user
print() – prints output to the console
CODE SAMPLE
2. Type Conversion Functions
Python provides built-in functions for converting data from one
type to another. These functions can be used to convert between
different data types, such as integers, floats, strings, and lists.
Some of the most commonly used type conversion functions in
Python include:
int() – converts a string or float to an integer
float() – converts a string or integer to a float
str() – converts any data type to a string
list() – converts any iterable to a list
CODE SAMPLE
Python object capable of returning its members one at a
time permitting it to be iterated over, in a for-loop
2. String Functions
Python also includes a number of built-in functions for
manipulating strings. Strings are a fundamental data type in
Python, and they are used extensively in programming. Some of
the most commonly used string functions in Python include:
len() – returns the length of a string
capitalize() – capitalizes the first letter of a string
replace() – replaces a specified substring with another
substring
split() – splits a string into a list of substrings based on a
specified delimiter
join() – joins a list of strings into a single string using a
specified delimiter
CODE SAMPLE
3. List Functions
Python includes a number of built-in functions for manipulating
lists. Lists are another fundamental data type in Python, and they
are used extensively in programming. Some of the most
commonly used list functions in Python include:
append() – adds an element to the end of a list
remove() – removes the first occurrence of a specified
element from a list
sort() – sorts the elements of a list
reverse() – reverses the order of the elements in a list
count() – returns the number of times a specified element
appears in a list
CODE SAMPLE
4. Dictionary Functions
Python dictionaries are another fundamental data type in
Python, and they are used extensively in programming.
Dictionaries are a collection of key-value pairs, and they can be
used to store and retrieve data efficiently. Some of the most
commonly used dictionary functions in Python include:
keys() – returns a list of all the keys in a dictionary
values() – returns a list of all the values in a dictionary
items() – returns a list of all the key-value pairs in a
dictionary
get() – returns the value associated with a specified key
pop() – removes the key-value pair associated with a
specified key
CODE EXAMPLE
5. Mathematical Functions: These are functions that can be
used to perform basic arithmetic operations. Some of the
most commonly used mathematical functions in Python
include:
1. abs() – returns the absolute value of a number
2. pow() – raises a number to a specified power
3. round() – rounds a number to a specified number of
decimal places
4. max() – returns the largest value in a list or tuple
5. min() – returns the smallest value in a list or tuple
CODE SAMPLE
6. File Handling Functions
Python provides built-in functions for handling files. These
functions can be used to open, read, write, and close files in
Python. Some of the most commonly used file handling
functions in Python include:
open() – opens a file and returns a file object
read() – reads the contents of a file
write() – writes data to a file
close() – closes a file object
CODE SAMPLE
1.3 CHARACTERISTICS OF BUILT IN FUNCTIONS
1. Always Available: There is no need to import libraries to
use built-in functions.
2. Versatile: Built-in functions cover a wide range of
operations, from basic input/output to complex
mathematical computations.
3. Optimized: They are built for high performance and
reliability, often implemented in C.
4. Ease of Use: Built-in functions are designed to make
Python code simpler and more readable.
1.4 ADVANTAGES OF BUILT-IN FUNCTIONS
1. Time-Saving: Pre-written and optimized for efficiency.
2. Readability: Reduce the need for extra code, making
scripts cleaner.
3. Performance: Often faster than equivalent user-defined
functions.
4. Versatility: Built-in functions are applicable in various
fields like data processing, web development, and
automation.
5. Consistency: They provide a consistent interface for
performing common operations, promoting best practices
and improving code quality across projects.
6. Cross-Platform: Built-in functions work consistently
across different operating systems, which simplifies
development and deployment.
1.6 LIMITATIONS OF BUILT-IN FUNCTIONS
1. Limited Flexibility: Built-in functions may not cover
every specific use case. For complex operations,
developers may need to write custom functions, which can
lead to additional overhead.
2. Learning Curve: While many built-in functions are
intuitive, some may have non-obvious behaviours or edge
cases that require additional learning and understanding.
For example map(), zip(), eval().
3. Performance Trade-offs: In some cases, built-in
functions may not be the most efficient choice for specific
tasks, especially if a custom implementation could be
optimized for particular data structures or algorithms.
4. Dependency on Standard Library: Relying too heavily
on built-in functions can lead to less familiarity with core
programming concepts, which may hinder a developer's
ability to solve problems without them.
5. Version Differences: Changes in built-in functions
between Python versions (e.g., deprecated functions or
changes in behaviour) can lead to compatibility issues
when upgrading codebases.
6. Overhead for Simple Tasks: For very simple tasks, using
built-in functions may introduce unnecessary overhead or
complexity, especially for beginners who may not
understand the function's behaviour fully.
1.7 APPLICATION OF BUILT-IN FUNCTIONS
1. Data Analysis and Processing:
len(): Determine the size of a dataset or list.
sum(), max(), min(): Perform basic statistical operations.
sorted(): Sort data for easier analysis.
Example:
Sorting sales figures to find top-performing products.
2. Web Development:
input(): Collect user input for forms or web-based tools.
str() and int(): Convert data types for query parameters.
open(): Read and write to configuration files or logs.
Example:
Capturing user preferences and storing them in a
configuration file
3. Machine Learning and AI:
zip(): Combine datasets like features and labels.
map(): Apply transformations to data.
all() and any(): Verify conditions across datasets.
Example:
Preprocessing data for training models
1.8 CONCLUSION
Built-in functions are a cornerstone of Python's design, offering
powerful, efficient tools for a wide range of tasks. Their
consistent use simplifies development, reduces errors, and
enhances performance, making Python a preferred choice for
programmers.
Desktop k6u