Various Built In Functions
Python ships with a rich set of built-in functions that are always available, without needing any import. Knowing these well saves you from writing custom code for common, everyday tasks.
Commonly Used Built-In Functions
len()- returns the number of items in a list, string, or other collectionrange()- generates a sequence of numbers, most often used in loopsmap()- applies a function to every item in an iterablefilter()- keeps only the items in an iterable that satisfy a conditionzip()- combines multiple iterables together, element by elementsorted()- returns a new sorted list from any iterableenumerate()- loops through an iterable while also tracking the index
names = ["Aman", "Priya", "Rohit"]
scores = [78, 92, 85]
for index, name in enumerate(names):
print(index, name)
for name, score in zip(names, scores):
print(name, "scored", score)
print(sorted(scores)) # [78, 85, 92]
print(sorted(scores, reverse=True)) # [92, 85, 78]
Relying on built-in functions instead of writing manual loops for common tasks generally makes your code shorter, faster, and easier for other developers to read.
Coming Up Next
With Python's functional toolkit covered, the course now shifts into Object Oriented Programming, starting with an introduction to its core concepts.