Introduction to Built-in Functions in Python

Welcome, explorer! Are you ready to venture into the realm of Python's built-in functions? These comprehensive tools can streamline your code, saving both time and effort. Our mission is to familiarize ourselves with some of Python's straightforward built-in functions. Let's embark on this journey!

Much like a built-in navigational system guiding astronauts, Python's built-in functions serve as accessible tools to navigate through coding tasks at any time. They operate as our guiding stars through the cosmic realm of programming.

Exploring Simple Python Built-in Functions: len()

Let's chart a course through Python's built-in functions:

The len() function: This function counts elements in a list, set, tuple, or any data structure, much like counting candies in a box:

candies_list = ['star1', 'star2', 'star3', 'star4']
print(len(candies_list))  # Output: 4

candies_set = {'star1', 'star2', 'star3', 'star4'}
print(len(candies_set)) # Output: 4

candies_tuple = ('star1', 'star2', 'star3', 'star4')
print(len(candies_tuple)) # Output: 4
Absolute value: abs()

The abs() function: Functioning like a device determining a spaceship's absolute distance in light years from a specific point in space, this function gives the absolute value of a number.

print(abs(-10))  # Output: 10
print(abs(7))    # Output: 7
Float numbers rounding: round()

The round() function: Similar to rounding off estimated distances or times, this function rounds a number to the nearest integer.

print(round(10.675))  # Output: 11
print(round(10.365)) # Output: 10
print(round(7.5)) # Output: 8
Minimal and Maximal Values: min() and max()

The min() and max() functions: These functions find the smallest and largest items in a list, set, or tuple, just as one might measure the smallest and largest star masses in a galaxy:

stars_list = [2.1, 3.2, 1.0, 5.4, 4.4]  # Sizes of stars
print(min(stars_list))  # Output: 1.0
print(max(stars_list))  # Output: 5.4

stars_set = {2.1, 3.2, 1.0, 5.4, 4.4}  # Sizes of stars
print(min(stars_set))  # Output: 1.0
print(max(stars_set))  # Output: 5.4

stars_tuple = (2.1, 3.2, 1.0, 5.4, 4.4)  # Sizes of stars
print(min(stars_tuple))  # Output: 1.0
print(max(stars_tuple))  # Output: 5.4
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal