Wednesday, November 19, 2025

7 Python Constructed-ins That Appear Like a Joke (Till You Use Them)


7 Python Constructed-ins That Appear Like a Joke (Till You Use Them)
Picture by Editor | ChatGPT

 

Introduction

 
Working with Python means counting on lots of its built-in features, particularly for knowledge science duties. Common features like len, max, vary, and many others., are widespread in an information scientist’s toolkit and helpful in numerous conditions. Nonetheless, many built-in features stay unrecognized as a result of they’re perceived as ineffective.

On this article, we are going to discover seven totally different built-ins that you just would possibly suppose are a joke however are literally very helpful of their purposes. These built-ins are totally different out of your normal code, however they’ll discover their place in your workflow when you understand their usefulness.

Curious? Let’s get into it.

 

1. The divmod Constructed-in Perform

 
Many individuals hardly ever use the divmod built-in operate, and even understand it exists. The divmod built-in operate returns two numbers: the results of flooring division and the modulus operation. It might appear ineffective since we are able to use syntax like a // b and a % b with out the necessity for the built-in, particularly once we hardly ever want each outcomes directly.

In real-world use instances, we regularly want each outcomes and wish them computed as soon as persistently to make the method quicker. Just a few divmod purposes — together with time conversion, pagination, batching, and cleaner hash math — present its utility.

Let’s see a utilization instance:

total_seconds = 7132
minutes, seconds = divmod(total_seconds, 60)
hours, minutes = divmod(minutes, 60)
print(f"Time: {hours:02d}:{minutes:02d}:{seconds:02d}")

 
The place the output is proven under:

 
With one operate, we are able to break up numbers evenly, which is helpful in lots of purposes.

 

2. The slice Constructed-in Perform

 
The slice built-in operate is used to separate or extract elements of sequences like strings, lists, or tuples. It might appear redundant as a result of we are able to merely create a slice object like obj[1:10:2].

Nonetheless, the energy of the slice built-in operate turns into obvious when you might want to reuse the identical slicing rule throughout numerous objects. The operate helps us keep constant parsing logic and permits us to construct methods for knowledge processing.

Right here is an instance for the implementation:

evens = slice(0, None, 2)
textual content = "abcdefghij"
print(textual content[evens])

 
The output is proven under:

 
The slice built-in above exhibits that we are able to set a reusable rule to take each second character.

 

3. The iter Constructed-in Perform

 
The iter built-in operate creates an iterator object that processes objects sequentially, one after the other. This may occasionally appear pointless since we have already got the `whereas True` and `break` sample. But, it’s useful because it permits for cleaner code and a greater construction within the knowledge pipeline.

For instance, we are able to use iter to regulate the streaming knowledge processing:

import io
f = io.BytesIO(b"12345678")

for block in iter(lambda: f.learn(3), b""):
    print(block)

 
The place the output is proven under:

 

4. The memoryview Constructed-in Perform

 
The memoryview built-in operate creates a reminiscence view object from inner knowledge with out copying it. It might seem to be an pointless operate that has no place in the usual Python workflow.

Nonetheless, the memoryview operate turns into helpful when dealing with giant binary knowledge as a result of it permits customers to entry and modify it with out creating a brand new object. For instance, you may exchange a portion of the information in the identical reminiscence with out copying, as proven within the following code.

buf = bytearray(b"hi there")
mv = memoryview(buf)
mv[0] = ord('H')
print(buf)
mv[:] = b"HELLO"
print(buf)

 
The output is proven under:

bytearray(b'Good day')
bytearray(b'HELLO')

 
The task is finished in the identical reminiscence, which is useful for any performance-sensitive work.

 

5. The any Constructed-in Perform

 
The any built-in operate returns a Boolean worth by checking objects in an iterable object. It returns True if any aspect within the iterable is truthy and False in any other case. The operate appears ineffective, because it seems to exchange a easy checking loop.

Nonetheless, the energy of the any operate lies in its potential to keep away from creating non permanent objects and to make use of lazy analysis with mills, which implies that the operate can have clear loop logic and scale back reminiscence utilization.

An instance of the Python code is proven under:

information = ["report.txt", "sales.csv", "notes.md"]
print(any(f.endswith(".csv") for f in information))

 
The place the output is proven under:

 
It is helpful when we’ve use instances that require validation or guard circumstances.

 

6. The all Constructed-in Perform

 
The all built-in operate is just like any, however the distinction is that the previous solely returns True if all objects within the iteration are truthy. Just like any, the all built-in operate is commonly perceived as ineffective since a guide loop can obtain the identical outcome.

It’s a invaluable built-in as a result of it supplies declarative and short-circuit verification that each aspect is truthy with lazy analysis for mills. Which means that the code is cleaner and takes much less reminiscence.

Instance utilization is utilizing the next code:

required = ["id", "name", "email"]
file = {"id": 1, "title": "Ana", "electronic mail": "a@x.io"}
print(all(okay in file for okay in required))

 
The place the output is proven under:

 
Purposes embody schema checks and enter validation.

 

7. The zip Constructed-in Perform

 
The zip built-in operate is used to combination components from a number of iterable objects into tuples. It might appear pointless, as a developer may merely iterate with indices, resembling with a for i in vary(len(x)): loop, or as a result of it solely returns tuples.

The zip built-in operate, nevertheless, is way extra useful as a result of it lets you loop over a number of iterable objects with out juggling indices. Because the operate creates pairs solely when vital, it is not going to waste reminiscence. It additionally avoids any widespread index errors once we manually handle the indexing.

The Python instance is proven under:

keys = ["id", "name", "email"]
vals = [1, "Ana", "a@x.io"]
file = dict(zip(keys, vals))
print(file)

 
The place the output is proven under:

{'id': 1, 'title': 'Ana', 'electronic mail': 'a@x.io'}

 
Many purposes exist, resembling for parallel iteration over datasets or pairwise computations with out index arithmetic.

 

Conclusion

 
Python is a helpful programming language for any data-related exercise, and its built-in features are a major a part of that utility. Nonetheless, some built-ins are perceived as ineffective — that’s, till you truly use them and understand simply how invaluable they’re.

I hope this has helped!
 
 

Cornellius Yudha Wijaya is an information science assistant supervisor and knowledge author. Whereas working full-time at Allianz Indonesia, he likes to share Python and knowledge suggestions by way of social media and writing media. Cornellius writes on a wide range of AI and machine studying subjects.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com