Mark As Completed Discussion

len()

We can find the length of a string, list, tuple, and a dictionary using the len() function. Let's create one of each and find their lengths.

PYTHON
1string = "Minahil"
2Flowers_List = ["Tulip", "Jasmine", "Rose", "Lili", "Daisy"]
3Number_Tuple = ("one", "two", "three")
4General_Dictionary = {
5    "key1": "value1",
6    "key2": "value2",
7    "key3": "value3",
8    "key4": "value4",
9}

Now, we will find the length using len() function.

PYTHON
1print("The length of string is", len(string))
2print("The length of list is", len(Flowers_List))
3print("The length of tuple is", len(Number_Tuple))
4print("The length of dictionary is", len(General_Dictionary))

The output will be:

PYTHON
1The length of string is 7
2The length of list is 5
3The length of tuple is 3
4The length of dictionary is 4
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment