A tutorial for finding the length of a string using len() in Python Programming Language
- The
len()function counts the number of characters in a given string and returns the long unsigned integer value. - It is an in-built function in Python PL.
- It returns the count of items in an object.
- When the object type is
string,len()function returns count of characters in the given string.
demoString = "Earth is a beautiful planet in Solar System";
len(demoString);
Working example
planet = "Earth", title = "MeshWorld";
print("Using len for planet: ", len(planet));
print("Using len for title: ", len(title));
Output
Using len for planet: 5
Using len for title: 9
Hope you like this!
Keep helping and happy ๐ coding
Related Articles
Deepen your understanding with these curated continuations.
How to Display Multiplication Tables in Python
Learn to generate multiplication tables in Python using for loops and the range() function. A perfect exercise for beginners to master iterative logic.
How to Generate Random Numbers in Python: A Quick Guide
Learn how to generate random integers and floats in Python using the random library. Master randint() and random() functions with simple code examples.
How to Check if a Variable is an Integer in Python
Learn how to check if a variable is an integer in Python using the type() and isinstance() functions. Essential for data validation and type-safe coding.