Always Five Trick → Class always returns 5 no matter what when you use len().

Always Five Trick → Class always returns 5 no matter what when you use len().

Leader posted 0 min read
class AlwaysFive:
    def __len__(self):
        return 5

a = AlwaysFive()
print(len(a))  # Always prints 5
If you read this far, tweet to the author to show them you care. Tweet a Thanks

More Posts

Advanced Python Concepts - Metaprogramming

Abdul Daim - Oct 10, 2024

Advanced Python Concepts - Networking with Python

Abdul Daim - Oct 8, 2024

Advanced Python Concepts - List Comprehensions

Abdul Daim - May 30, 2024

Resolved: Attributeerror: 'dataframe' object has no attribute 'reshape'

Honey - Jun 20, 2024

[Python Error] modulenotfounderror: no module named 'sklearn.cross_validation' [Solved]

Muzzamil Abbas - Feb 15, 2024
chevron_left