Built-in Functions
Python comes with dozens of built-in functions β no import needed. They help you transform, measure, or convert values in one line of code.
In this chapter, weΡll group these functions by purpose β numbers, text, types, and collections.
- Give code examples using int, float, str, and bool to convert different types.
- Give code examples using abs and round with different numbers.
- Give code examples using lower, strip, replace, split, and join on strings.
- Give code examples using len, max, min, and sum with a list of numbers.
- Give code examples using enumerate, zip, map, and filter with lists.
Converting Data Types
These functions let you convert between basic types:
int()
β to integer;float()
β to float;str()
β to string;bool()
β to Boolean.
Useful when working with input, formatting, or expressions.
Working with Numbers
These help clean or adjust numeric values:
abs()
β absolute value (removes minus sign);round()
β rounds floats to nearest whole or to decimals.
Working with Strings
These are commonly used for cleaning and formatting text:
lower()
β make all letters lowercase;upper()
β make all letters uppercase;strip()
β remove spaces at the beginning and end;replace()
β replace part of a string with another;split()
β turn a string into a list of words;join()
β combine list items into one string.
Collection Inspection
These return information about a list, tuple, or other iterable:
len()
β count items;max()
β largest value;min()
β smallest value;sum()
β total of all numbers.
Collection Transformation
These are helpful when looping, combining, or transforming collections:
sorted()
β returns sorted list;enumerate()
β adds index numbers;zip()
β pairs items from multiple lists;range()
β creates a sequence of numbers;map()
β applies a function to each item;filter()
β keeps items that meet a condition.
Summary
- Python's built-in functions save you time and code;
- You can convert data, adjust text, transform collections, and get answers instantly;
- These tools become essential as you build more complex programs.
Try It Yourself
- Convert the string
"42"
to an integer usingint()
, and then to a float usingfloat()
; - Use
abs()
andround()
on the number-5.8
to clean and format it; - Take the string
" Hello, World! "
and applystrip()
,lower()
, andreplace()
to tidy and modify it; - Create a list of numbers:
[3, 7, 2, 9]
. Uselen()
,max()
, andsum()
to inspect it; - Use
enumerate()
to loop over the list and print both index and value. Then usemap()
to double each item.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 5
Built-in Functions
Swipe to show menu
Python comes with dozens of built-in functions β no import needed. They help you transform, measure, or convert values in one line of code.
In this chapter, weΡll group these functions by purpose β numbers, text, types, and collections.
- Give code examples using int, float, str, and bool to convert different types.
- Give code examples using abs and round with different numbers.
- Give code examples using lower, strip, replace, split, and join on strings.
- Give code examples using len, max, min, and sum with a list of numbers.
- Give code examples using enumerate, zip, map, and filter with lists.
Converting Data Types
These functions let you convert between basic types:
int()
β to integer;float()
β to float;str()
β to string;bool()
β to Boolean.
Useful when working with input, formatting, or expressions.
Working with Numbers
These help clean or adjust numeric values:
abs()
β absolute value (removes minus sign);round()
β rounds floats to nearest whole or to decimals.
Working with Strings
These are commonly used for cleaning and formatting text:
lower()
β make all letters lowercase;upper()
β make all letters uppercase;strip()
β remove spaces at the beginning and end;replace()
β replace part of a string with another;split()
β turn a string into a list of words;join()
β combine list items into one string.
Collection Inspection
These return information about a list, tuple, or other iterable:
len()
β count items;max()
β largest value;min()
β smallest value;sum()
β total of all numbers.
Collection Transformation
These are helpful when looping, combining, or transforming collections:
sorted()
β returns sorted list;enumerate()
β adds index numbers;zip()
β pairs items from multiple lists;range()
β creates a sequence of numbers;map()
β applies a function to each item;filter()
β keeps items that meet a condition.
Summary
- Python's built-in functions save you time and code;
- You can convert data, adjust text, transform collections, and get answers instantly;
- These tools become essential as you build more complex programs.
Try It Yourself
- Convert the string
"42"
to an integer usingint()
, and then to a float usingfloat()
; - Use
abs()
andround()
on the number-5.8
to clean and format it; - Take the string
" Hello, World! "
and applystrip()
,lower()
, andreplace()
to tidy and modify it; - Create a list of numbers:
[3, 7, 2, 9]
. Uselen()
,max()
, andsum()
to inspect it; - Use
enumerate()
to loop over the list and print both index and value. Then usemap()
to double each item.
Thanks for your feedback!