Find the length of built-in Sequences
A container having ordered objects is called a sequence. Python has three fundamental built-in sequences: lists, tuples, and strings. We can find the length of these objects by using Python len() Function. Let’s take some examples:
Code:
Python3
list1 = [ 'geeks' , 'for' , 'geeks' , 2022 ] # printing length of list1 print ( len (list1)) tuple1 = ( 1 , 2 , 3 , 4 ) # printing length of tuple1 print ( len (tuple1)) string1 = "w3wiki" # printing length of string1 print ( len (string1)) |
Output:
4 4 13
Python len() Function
Python len() function is an inbuilt function in Python. It can be used to find the length of an object.
Python len() function Syntax:
len(Object)
Parameter:
- Object: Object of which we have to find the length for example string, list, etc.
Returns: It returns the integer value which indicates the length of an object.
For example, we can find the total number of characters in a string using the Python len() Function. It can be used with different types of data types except some of them.
Example:
Input: "w3wiki" Output: 13 Explanation: The input string contains 13 characters so output is 13.