Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Built-in Functions | Functions & Modularity
Introduction to Python with AI

bookBuilt-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.

Note
Note
  • 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

  1. Convert the string "42" to an integer using int(), and then to a float using float();
  2. Use abs() and round() on the number -5.8 to clean and format it;
  3. Take the string " Hello, World! " and apply strip(), lower(), and replace() to tidy and modify it;
  4. Create a list of numbers: [3, 7, 2, 9]. Use len(), max(), and sum() to inspect it;
  5. Use enumerate() to loop over the list and print both index and value. Then use map() to double each item.
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 5

bookBuilt-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.

Note
Note
  • 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

  1. Convert the string "42" to an integer using int(), and then to a float using float();
  2. Use abs() and round() on the number -5.8 to clean and format it;
  3. Take the string " Hello, World! " and apply strip(), lower(), and replace() to tidy and modify it;
  4. Create a list of numbers: [3, 7, 2, 9]. Use len(), max(), and sum() to inspect it;
  5. Use enumerate() to loop over the list and print both index and value. Then use map() to double each item.
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1
some-alt