Reasons to Use Python Len Function
There can be many more reasons why you might want to use the len() function.
- You might want to iterate a function for each item in data, in that case we can know how many items there are. (Usually in Python loops which we will see later)
- You might want to build a conditional statement based on the size of data (Python conditional statements which we will see later)
- You might only be interested in words bigger than a specific length (length of strings)
- You might want to make sure your data is bigger than a certain size (Imagine a Python script that collects data and only writes this collection to a file once a specific length is reached)
- You might want to make sure your range calculation is correct (len function also works with range object another concept we will see later.)
- Long story short, there can be many reasons why you might want to use len function to find out the length of strings, lists, tuples, dictionaries and range objects.
Some or all of these situations may occur during any programming task such as operating system operations, scripting, web scraping, data science, working on financial data, digital image manipulation etc.